Quick links: Content - sections - sub sections
EN

Trace: 1.6.x

Differences

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

Link to this comparison view

Next revision
Previous revision
en:tutorials:main:database-config [2007/09/16 06:45] – created laurenten:tutorials:main:database-config [2008/11/19 21:42] (current) laurent
Line 1: Line 1:
-====== Configuring the database access ====== 
  
-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+Before going further with code, you have to configure Jelix to be able to access a database, and feed this database a 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). 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 ===== ===== 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.+The access to a database is configured in the news.org/var/config/dbprofils.ini.php file. In this file, you can specify one or more connection profiles, then one or more connections.
  
-Each profile has a name and is  specified like this :+Each profile has a name and are specified like this :
  
 <code ini> <code ini>
 [ProfileName] [ProfileName]
 driver="mysql"    ; name of the driver to use driver="mysql"    ; name of the driver to use
-database="foo"    ; name of the base to use +database="foo"    ; name of the database to use 
-host= "localhost"name of the machine of the database server +host= "localhost"hostname or ip to database server 
-user= "john"      ; connexion user+user= "john"      ; connection user
 password="doo"    ; password password="doo"    ; password
-persistent= on    ; indicating if the connexion is persistent+persistent= on    ; indicating if the connection is persistent 
 +force_encoding = off;
 </code> </code>
  
-Except the dirver parameterwhich 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.+Except the driver parameter which is mandatory, the other parameters depends on the driver which are used. In general, you will have the database, host, user and password parameters.  
 + 
 +Now change the content of this file according to your configuration. We will take as profile name "news.org" for example, and we will define this profile as the default one by specifying it with the "default" parameter.
  
 <code ini> <code ini>
-default = actu.org+default = news.org
  
-[actu.org]+[news.org]
 driver="mysql" driver="mysql"
-database="actu"  +database="news"  
 host= "localhost" host= "localhost"
-user= "actu   +user= "admin   
-password="actu"+password="news"
 persistent= on  persistent= on 
 </code> </code>
  
-Check in the actu.org/var/config/config.classic.ini.php file that the dbprofil parameter shows the dbprofils.ini.php clearly.+ 
 +Note: It is indeed sometimes interesting to have several entry points, then several settings sharing the same connection profiles file, or that each one has its own connections file If you want to have different configuration files for the database access, create other ini files, and push their name in the **dbProfils** option in the configuration file of the entry point.
  
 <code ini> <code ini>
- dbProfils = dbprofils.ini.php+ dbProfils = other_dbprofils.ini.php
 </code> </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 ===== ===== Creation of the table =====
  
-In the "actubase, we will now create a news table. Execute this sql script (adapt it if you are not using mysql):+In the "newsdatabase, we will now create a "newstable. Execute this sql script (adapt it if you are not using mysql):
  
 <code sql> <code sql>
  
 CREATE TABLE `news` ( CREATE TABLE `news` (
-`id_news` INT NOT NULL AUTO_INCREMENT ,+`news_id` INT NOT NULL AUTO_INCREMENT ,
 `subject` VARCHAR( 255 ) NOT NULL , `subject` VARCHAR( 255 ) NOT NULL ,
 `text` TEXT NOT NULL , `text` TEXT NOT NULL ,
 `news_date` DATE NOT NULL , `news_date` DATE NOT NULL ,
-PRIMARY KEY ( `id_news` )+PRIMARY KEY ( `news_id` )
 ); );
 </code> </code>
  
-And feed this table avec deux news (we will make a form later).+And feed this table with two news (we will make a form later).
  
 <code sql> <code sql>
Line 72: Line 70:
 We are now ready to use this data in our application. We are now ready to use this data in our application.
  
----- 
-   * Next : [[en:tutorials:main:using-dao|Using a DAO]] 
-   * Previous : [[en:tutorials:main:creating-action|Creating an action]] 
-   * [[en:tutorials:main|Back to the summary]] 

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

Recent changes RSS feed Creative Commons License