Quick links: Content - sections - sub sections

Trace: database-config

Wiki: Sitemap - Recent Changes - Back link

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.

Access configuration file

The access to a database is configured in the news.org/var/config/profiles.ini.php file. In this file, you can specify one or more connection profiles.

Each profile has a name and are specified like this :

driver="mysqli"    ; name of the driver to use
database="foo"    ; name of the database to use
host= "localhost" ; hostname or ip to database server
user= "john"      ; connection user
password="doo"    ; password
persistent= on    ; indicating if the connection is persistent
force_encoding = off;

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.

default = news.org
host= "localhost"
user= "admin"   
persistent= on 

Creation of the table

In the “news” database, we will now create a “news” table. Execute this sql script (adapt it if you are not using mysql):

`subject` VARCHAR( 255 ) NOT NULL ,
`text` TEXT NOT NULL ,
`news_date` DATE NOT NULL ,
PRIMARY KEY ( `news_id` )

And feed this table with two news (we will make a form later).

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');

We are now ready to use this data in our application.

en/tutorials/jelixnews-1.7/database-config.txt · Last modified: 2019/05/23 11:51 (external edit)
Recent changes RSS feed Creative Commons License