ZMDatabase
public interface ZMDatabase
| Field Summary | |
|---|---|
| final mixed | Internal date-time format. |
| final mixed | Internal date format. |
| final mixed | If used as modelClass parameter, the raw SQL data will be returned (no mapping, etc). |
| final mixed | NULL date. |
| final mixed | NULL datetime. |
| Method Summary | |
|---|---|
| void | Start a transaction. |
| void | commit() Commits statements in a transaction. |
| mixed | createModel(string table, mixed model, mixed mapping) Create a single row using the given model and mapping. |
| array | Get the configuration settings for this instance. |
| array | getMetaData(string table) Get meta data. |
| mixed | Get the underlying, implementation specific resource used to access the database. |
| array | getStats() Get some stats about database usage. |
| mixed | loadModel(string table, mixed key, string modelClass, mixed mapping) Load a single row using the given model and mapping. |
| array | query(string sql, array args, string modelClass, mixed mapping) Execute a query. |
| mixed | querySingle(string sql, array args, string modelClass, mixed mapping) Execute a query expecting a single result. |
| void | removeModel(string table, mixed model, mixed mapping) Remove a single row using the given model and mapping. |
| void | rollback() Rollback changes in a transaction. |
| int | update(string sql, mixed data, mixed mapping) Update using the provided SQL and data and model. |
| void | updateModel(string table, mixed model, mixed mapping) Update a single row using the given model and mapping. |
public final mixed DATETIME_FORMAT = 'Y-m-d H:i:s'
Internal date-time format. */
public final mixed DATE_FORMAT = 'Y-m-d'
Internal date format. */
public final mixed MODEL_RAW = '@raw'
If used as modelClass parameter, the raw SQL data will be returned (no mapping, etc). */
public final mixed NULL_DATE = '0001-01-01'
NULL date. */
public final mixed NULL_DATETIME = '0001-01-01 00:00:00'
NULL datetime. */
public void beginTransaction()
Start a transaction.
If the database provider (and database driver) allow, nested transaction are possible.
public void commit()
Commits statements in a transaction.
public mixed createModel(string table, mixed model, mixed mapping)
Create a single row using the given model and mapping.
null.public array getConfig()
Get the configuration settings for this instance.
public array getMetaData(string table)
Get meta data.
Meta data is available for either the current database or, if specified, an individual table.
The following table information will be returned:
ZMDatabase API.null.public mixed getResource()
Get the underlying, implementation specific resource used to access the database.
public array getStats()
Get some stats about database usage.
public mixed loadModel(string table, mixed key, string modelClass, mixed mapping)
Load a single row using the given model and mapping.
null.null.public array query(string sql, array args, string modelClass, mixed mapping)
Execute a query.
If $resultClass is null, the returned
list will contain a map of columns => value for each selected row.
$modelClass may be set to the magic value of ZMDatabase::MODEL_RAW to force
returning the raw data without applying any mappings or conversions.
null.null.$resultClass or map if modelClass is null.public mixed querySingle(string sql, array args, string modelClass, mixed mapping)
Execute a query expecting a single result.
$modelClass may be set to the magic value of ZMDatabase::MODEL_RAW to force
returning the raw data without applying any mappings or conversions.
null.null.nullpublic void removeModel(string table, mixed model, mixed mapping)
Remove a single row using the given model and mapping.
null.public void rollback()
Rollback changes in a transaction.
public int update(string sql, mixed data, mixed mapping)
Update using the provided SQL and data and model.
null.public void updateModel(string table, mixed model, mixed mapping)
Update a single row using the given model and mapping.
null.
ZenMagick database abstractation.
A generic, lightweight database layer.
As a convention, implementation classes must support an array as single constructor argument. This array (or map) will contain the connection details.
Support for the following array keys is required:
The data will be bound to the SQL using the configured table mappings.
It is also possible to generate table mappings on the fly. In that case no name translation will be done.
Syntax for parameters in SQL is: :{[0-9]+#}[propertyName]. The numeric prefix (for example
:3#categoryId) is optional and only required if multiple values of a column are used in a single SQL statement.