Quick links: Content - sections - sub sections
EN FR

Managing schemas

The class jDbSchema allow you to manipulate the structure of the database. It have some methods to create a table, to retrieve the structure of a table, to add/modify/remove columns etc. It uses some other classes: jDbTable and jDbColumn.

Until Jelix 1.6.16, jDbSchema was experimental and only Mysql was supported. Since Jelix 1.6.16, Postgresql, Mysql and sqlite3 are fully supported.

You can retrieve a jDbSchema object by calling the method schema() of a jDbConnection object.

See the API documentation.

Executing an SQL script

If you want to execute a SQL script containing several queries, you can call the execSQLScript() method of the object jDbTools. You retrieve this object by calling the method tools() of a connection object.


  $conn = jDb::getConnection();
  $conn->tools()->execSQLScript('/path/to/a/script.sql');

In order to use the table prefix indicated in the profile, it is strongly recommended to use the %%PREFIX%% tag before each name of tables. It will be replaced by the prefix (or by nothing if there is no prefix).


UPDATE %%PREFIX%%product.....;
INSERT .....;

jDbWidget

jDbWidget is a class providing useful methods.


  $dbw = jDb::getDbWidget(); // instead of getConnection()

  $record = $dbw->fetchFirst("SELECT name, first_name FROM user");
  
  $liste = $dbw->fetchAll("SELECT name, first_name FROM user");

For other methods of jDbWidget, see the API reference.