Working with table rows and the elxisDbTable class
elxisDbTable is an abstact class that allows you to easily handle database table rows as objects. elxisDbTable extensions for the built-in extensions are stored inside the includes/libraries/elxis/database/tables/ folder. For the third party extensions they can be placed anywhere in Elxis filesystem. Moreover Elxis provides cross-database table definition system.
The most important methods of the elxisDbTable class
Load a table row as object by providing the value of the primary key column ($id)
Bind an array (usually $_POST) to elxisDbTable object
Get the database table name
Get the columms of the current table name as array
Get the name of the table's primary key column
Force new row. Be careful for dublicated entries if $reset_primary is false
Insert or update table row. For new rows an insert is executed, for existing ones an update.
Insert a new row into the database.
Update a row.
Copy current row and save it into the database with a new primary key.
Delete current row or any row by providing the primary key value.
Move (re-order) a row one position UP or DOWN. Returns true on success, false on error.
$inc should be -1 to move row up and 1 to move it down.
$wheres is an array of conditional statements to be passed in the SQL query.
Each element of this array is an array with 3 arguments:
- Column name
- Operator (available options: =, >, >=, <, <= and LIKE)
- Value
The AND operator will be used to join the $wheres elements.
Reorder rows in a table.
Checks the validity of the row column values before an insert or update and returns true or false.
Returns table's or database's last error message.
You can create extensions of the elxisDbTable like this:
Note the DbTable suffix in the class name. The constructor of the customDbTable class should set the table name and table primary key in the parent class as well as define the table columns. The class can also have a check method that will be called automatically by the parent class during insert/update/store to validate the data before trying to save them.
In the constructor of the extension class you can define the table columns by providing an array to the columns property. This array must have as keys the column name and as values an array with the column type and initial value. The supported column types are the following:
A generic table handler.
Develop engines to extend Elxis search to anything you can imagine