![]() |
|
MySql query abstractions. Base for all database models. More...
Public Member Functions | |
Model ($db_connection) | |
setTable ($table) | |
getPrimaryKey () | |
where ($val, $logical_operator= 'and', $compare_sign= '=') | |
whereIn ($value, $invalues, $not=false) | |
values ($values=null) | |
setValues ($values) | |
select ($conditions="", $values=null) | |
selectRow ($primary_value) | |
selectRows ($options=array()) | |
insert ($values) | |
updateRow ($values, $primary_value) | |
updateRows ($values, $where="") | |
deleteRow ($primary_value) | |
deleteRows ($where="") | |
countRows ($options="") | |
![]() | |
DataBaseMySql ($db_connection) | |
connection () | |
query ($query) | |
execute ($query) | |
nextObject ($result=null) | |
numRows ($result=null) | |
affectedRows () | |
queryOneRow ($query) | |
lastId () | |
getQueriesCount () | |
resetRow ($result=null) | |
close () | |
![]() | |
Dispersion () | |
emptyLayout () | |
set ($name, $value) | |
_set ($name, $value) | |
insertView ($name, $index=-1) | |
Data Fields | |
$_primary_key = null | |
$table | |
![]() | |
$_connection = null | |
$defaultDebug | |
$nr_queries | |
$last_result | |
$sql_affected_rows | |
![]() | |
$model_ob = null | |
$debug_ob = null | |
$_variables = array() | |
$_content = array() | |
$_content_count = 0 | |
$model | |
$debug | |
Additional Inherited Members | |
![]() | |
requireConfigFile ($file_name, $required=false) | |
MySql query abstractions. Base for all database models.
Query with one result
Execute query and get number of affected rows.
Query with one result
The table used with the following methods is by default the same as the name of the model, or can be set using the Model::setTable() method.
Selecting, or executing simple selection queries can be done using the select()
method :
Advanced selection can be done by using Model::selectRows
Selecting a single row can be done either by a given primary key, or by a where clause, depending on the type of the $condition
. In case $condition
is not an array, the primary key is obtained automatically and compared with the given parameter. Otherwise the where clause is used.
A table where the primary key is id
will create the following queries :
Model | ( | $db_connection | ) |
Constructor
$db_connection | array : db connection information |
setTable | ( | $table | ) |
Set the default table
$table | string : The table name |
getPrimaryKey | ( | ) |
Helper, get the primary key of the table
where | ( | $val, | |
$logical_operator = 'and' , |
|||
$compare_sign = '=' |
|||
) |
Generate a query where clause
$val | string/array : array of values, or a string containing the query |
$logical_operator | string : the default operator to be used between comparisons |
$compare_sign | string : the default sign used for comparisons |
whereIn | ( | $value, | |
$invalues, | |||
$not = false |
|||
) |
Generate a query where_in clause
$value | string : the value to look for |
$invalues | array : the values to look in |
$not | boolean : if set to true, the value will not be contained |
values | ( | $values = null | ) |
Generate a query string with comma separated values
$values | array/string |
setValues | ( | $values | ) |
Generate a query string with comma separated values to be set
$values | array/string : if array, the values must have keys to match upon |
select | ( | $conditions = "" , |
|
$values = null |
|||
) |
Quick select
$conditions | string/array : passed to the 'where' method if given |
$values | string/array : passed to the 'values' method if given |
selectRow | ( | $primary_value | ) |
Select a row based on a where clause or a primary key
$primary_value | string/array : if array, it will pe passed to the 'where' method, otherwise it will be matched with the primary key of the table |
selectRows | ( | $options = array() | ) |
Advanced select
array | $options | : an array with specified keys as options
|
insert | ( | $values | ) |
Inserts given values
$values | string/array : parsed by the 'setValues' method |
updateRow | ( | $values, | |
$primary_value | |||
) |
Update one row by its primary key
$values | array/string : parsed by the 'setValues' method |
$primary_value | string/numeric : the value of the primary key |
updateRows | ( | $values, | |
$where = "" |
|||
) |
Update rows
$values | array/string : parsed by the 'setValues' method |
$where | array/string : parsed by the 'where' method |
deleteRow | ( | $primary_value | ) |
Delete row by its primary key
$primary_value | string/numeric : value of the primary key |
deleteRows | ( | $where = "" | ) |
Deletes rows selected by a where clause
$where | string/array : parsed by the 'where' method |
countRows | ( | $options = "" | ) |
Count the total rows in a table
$options | array : parsed by the 'selectRows' method |
$options | string : added at the end of the query |
$_primary_key = null |
string : Holds the primary key of the table, used by functions that request or change one row. Can be set, or fetched by getPrimaryKey() method.
$table |
string : Name of the table the model will be working with