Working with the database in Elxis and the elxisDatabase library.
Elxis uses PHP's native PDO extension for accessing and managing the database. Elxis has built in support for many database types sych as MySQL, PostgreSQL, MsSQL, Oracle, Firebird and SQLite although it is thoughrogly tested only with MySQL. In this article we will provide a general presentation of the PDO's implementation in Elxis and documentation for the main, elxisDatabase class.
The Elxis database library (elxisDatabase) is the main class for accessing the database. Elxis has a number of help classes under the includes/libraries/elxis/database/ path which are used for various tasks. Let's see how the whole system is organized.
File: includes/libraries/elxis/database.class.php
Get elxisDatabase instance by calling the getDB method of Elxis Factory:
File: includes/libraries/elxis/database/adapter.class.php
Dir: includes/libraries/elxis/database/adapters/
Class name format: elxisDatabase typeAdapter
Class elxisPDOStatement is an extension of the PHP's PDOStatement class.
File: includes/libraries/elxis/database/statement.class.php
A class for handling database tables.
File: includes/libraries/elxis/database/table.class.php
Dir: includes/libraries/elxis/database/tables/
Implementations for built-in extensions can be found ib the directory shown above. For the third party extensions it is up to the developer where he will place them inside his extension.
Class name format: table nameDbTable (actually table name can be anything but we recommend using something representative of the actual database table name)
A class for importing data into the database.
File: includes/libraries/elxis/database/importer.class.php
Dir: includes/libraries/elxis/database/importers/
Class name format: elxisDatabase typeImporter
The public methods of the elxisDatabase class
A magic constructor for the elxisDatabase class. You can connect to a database directly from the constructor or from the connect method (see below). $params contains an array of connection settings. If not defined the values from the configuration file are used. $options is an optional array of parameters to be passed to the PDO class on connection. $connect (true/false) connect immediately to the database or not.
Connect to the database
Disconnect from the database
Returns an array of PDO's available drivers on the system.
Returns a PDO's attribute value.
Sets the value of a PDO attribute.
Returns current adapter (database type) version.
Get the last Id generated by an auto-increment column.
Quotes a string depending on the current adapter.
Quotes an identifier (database table name or column name) depending on the current adapter.
Prepares a statement for execution and returns a statement object. It calls internally the prepare method of the elxisPDOStatement class.
As for prepare but with limit capabilities (PDO lucks support for limiting results).
Replaces SQL prefix with the real database tables prefix. Normally this is called internally by prepare and prepareLimit methods so you never have to use it.
Adds limit instructions to an SQL query. Normally this is called internally by prepareLimit method so you never have to use it.
Returns an array of table names in the database.
Performs an SQL backup on selected or all database tables. Returns SQL data on success or 0 (fail), -1 (not supported database), -2 (Invalid/Insuficient backup parameters), -3 (other db specific error)
Import an SQL file into the database. The file should be properly formatted for the current database type. Use #__ in SQL file as tables prefix replacements. Note that you can alternatively use the elxisDbImporter library.
Execute a query and return result as PDO statement.
Execute SQL query and return number of affected rows.
Develop engines to extend Elxis search to anything you can imagine