(Created page with "In Gfx there's the static class EDatabase which, if enabled, loads at the start of the script. It makes uses of a configuration file called ''database.conf.php'' that must con...")
 
 
Line 1: Line 1:
In Gfx there's the static class EDatabase which, if enabled, loads at the start of the script. It makes uses of a configuration file called ''database.conf.php'' that must contain correct values of a MySQL database. Works on more db drivers is in the roadmap.
+
In Gfx database is abstracted using the multipurpose class EModel which queries the correct database driver.
 +
More database drivers are coming, though. Mysql driver is fully functional, sqlite driver is work in progress.
  
 
Small reference:
 
Small reference:
  
* '''EDatabase::q($sql_query)''' -> execute $sql_query
+
* '''EMysql::q($sql_query)''' -> execute $sql_query
* '''EDatabase::sq($sql_query)''' -> execute $sql_query and returns the first result. Useful for counts etc.  
+
* '''EMysql::sq($sql_query)''' -> execute $sql_query and returns the first result. Useful for counts etc.  
* '''EDatabase::table_exists($table)''' -> check if table exists and return boolean.
+
* '''EMysql::table_exists($table)''' -> check if table exists and return boolean.
* '''EDatabase::last_insert_id()''' -> returns the id of the last inserted row.
+
* '''EMysql::last_insert_id()''' -> returns the id of the last inserted row.
  
 
Database functionalities can be enabled/disabled in the generic config file ("config/generic.conf.php"):
 
Database functionalities can be enabled/disabled in the generic config file ("config/generic.conf.php"):
Line 14: Line 15:
 
database|yes
 
database|yes
 
database|no
 
database|no
 +
databasedriver|EMysql
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
'''databasedriver''' can also be ESQLite, but support for SQLite database is still not complete. To use the correct database abstraction please use EModel class (standalone o subclassed).
  
 
------
 
------

Latest revision as of 13:21, 20 May 2016

In Gfx database is abstracted using the multipurpose class EModel which queries the correct database driver. More database drivers are coming, though. Mysql driver is fully functional, sqlite driver is work in progress.

Small reference:

  • EMysql::q($sql_query) -> execute $sql_query
  • EMysql::sq($sql_query) -> execute $sql_query and returns the first result. Useful for counts etc.
  • EMysql::table_exists($table) -> check if table exists and return boolean.
  • EMysql::last_insert_id() -> returns the id of the last inserted row.

Database functionalities can be enabled/disabled in the generic config file ("config/generic.conf.php"): Example:

<?php die("You cannot see config in here."); ?>
database|yes
database|no
databasedriver|EMysql

databasedriver can also be ESQLite, but support for SQLite database is still not complete. To use the correct database abstraction please use EModel class (standalone o subclassed).


database.conf.php

Example of a valid configuration file:

<?php die(); ?>
name|test
host|localhost
user|root
password|asd

This page was last edited on 20 May 2016, at 13:21. Content is available under Creative Commons License SA 4.0 unless otherwise noted.