Quick links: Content - sections - sub sections
EN

Trace:

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:tutorial:database-config [2006/11/08 11:05] – (old revision restored) 127.0.0.1en:tutorial:database-config [2007/09/17 22:42] (current) – external edit 127.0.0.1
Line 1: Line 1:
-====== Configuring the database access ====== +This page has been moved to [[en:tutorials:main:database-config]]
- +
-Before going further with code, you have to configure Jelix to be able to access a database, and feed this databasea little bit. We will indeed store our news in a table +
- +
-Jelix can handle mysql, postgresql, sqlite and pdo. Through its driver system, it is possible to add other types of databases (if you don't want to use pdo). +
- +
- +
- +
-===== Access configuration file ===== +
- +
-The access to a database is configured in the actu.org/var/config/dbprofils.ini.php file. In this file, you can specify one or several connexion profiles, then one ore several connexions. +
- +
-Each profile has a name and is  specified like this : +
- +
-<code ini> +
-[ProfileName] +
-driver="mysql"    ; name of the driver to use +
-database="foo"    ; name of the base to use +
-host= "localhost" ; name of the machine of the database server +
-user= "john"      ; connexion user +
-password="doo"    ; password +
-persistent= on    ; indicating if the connexion is persistent +
-</code> +
- +
-Except the dirver parameter, which is mandatory, the other parameters depend on the driver which is used. In general, you will have the database, host, user and password parameters. Change the content of this file according to your configuration. We will take as profile name "actu.org" for example, and we will define this profile as the default one by specifying it with the "default" parameter. +
- +
-<code ini> +
-default = actu.org +
- +
-[actu.org] +
-driver="mysql" +
-database="actu"   +
-host= "localhost" +
-user= "actu"    +
-password="actu" +
-persistent= on  +
-</code> +
- +
-Check in the actu.org/var/config/config.classic.ini.php file that the dbprofil parameter shows the dbprofils.ini.php clearly. +
- +
-<code ini> +
- dbProfils = dbprofils.ini.php +
-</code> +
- +
-It is indeed sometimes interesting to have several entrance points, then several  settings sharing the same connexion profiles file, or that each one has its own connexions file. +
- +
- +
- +
-===== Creation of the table ===== +
- +
-In the "actu" base, we will now create a news table. Execute this sql script (adapt it if you are not using mysql): +
- +
-<code sql> +
- +
-CREATE TABLE `news` ( +
-`id_news` INT NOT NULL AUTO_INCREMENT , +
-`subject` VARCHAR( 255 ) NOT NULL , +
-`text` TEXT NOT NULL , +
-`news_date` DATE NOT NULL , +
-PRIMARY KEY ( `id_news` ) +
-); +
-</code> +
- +
-And feed this table avec deux news (we will make a form later). +
- +
-<code sql> +
-INSERT INTO `news` VALUES (1, 'first news', 'This is a first news. In commodo, neque sit amet laoreet accumsan, neque velit rutrum augue, a fringilla nibh lorem nec est. Cras eleifend eros. Sed vehicula. Donec vel enim at nunc tincidunt pellentesque. Donec malesuada. Praesent volutpat orci ut leo. Donec dictum tortor quis odio. Aliquam pulvinar justo eu eros.', '2006-01-15'); +
- +
-INSERT INTO `news` VALUES (2, 'Lorem Ipsum', 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse enim elit, luctus in, rhoncus quis, facilisis in, nulla. Nam eu dolor vel erat semper porta. Phasellus pellentesque nulla a urna. Phasellus nonummy diam id risus. Donec faucibus mi sed nisi. Sed et lectus at ligula scelerisque tempus. Proin justo nibh, consectetuer porta, accumsan ac, consectetuer id, dui. Morbi at mi auctor urna elementum convallis. Etiam et massa porta risus imperdiet ullamcorper. Aenean a metus at tortor ultrices accumsan. Mauris luctus.', '0000-00-00'); +
-</code> +
- +
-We are now ready to use this data in our application. +
- +
----- +
-   * Next : [[en:tutorial:using-dao|Using a DAO]] +
-   * Previous [[en:tutorial:creating-action|Creating an action action]] +
-   * [[en:tutorial|Back to the summary]]+

en/tutorial/database-config.1162983922.txt.gz · Last modified: 2007/09/17 22:42 (external edit)

Recent changes RSS feed Creative Commons License