This class contains functions for database driver handling in CONTENIDO.
| package | Core |
|---|---|
| subpackage | Database |
__construct(array $options) : void
Uses default connection settings, passed $options['connection'] settings will overwrite connection settings for current instance.
arrayAssoziative options as follows: - $options['haltBehavior'] (string) Optional, halt behavior on occured errors - $options['haltMsgPrefix'] (string) Optional, Text to prepend to the halt message - $options['enableProfiling'] (bool) Optional, flag to enable profiling - $options['connection'] (array) Optional, assoziative connection settings - $options['connection']['host'] (string) Hostname or ip - $options['connection']['database'] (string) Database name - $options['connection']['user'] (string) User name - $options['connection']['password'] (string) User password
__get(string $name) : mixed
stringname of the variable
mixedaffectedRows() : int
intNumber of affected rowsbuildInsert(string $tableName, array $fields) : string
String values in passed fields parameter will be escaped automatically.
Example:
$db = cRegistry::getDb();
$fields = array(
'idcode' => $idcode,
'idcatart' => $idcatart,
'idlang' => $lang,
'idclient' => $client,
'code' => "... code n' fun ...",
);
$statement = $db->buildInsert($cfg['tab']['code'], $fields);
$db->query($statement);
stringThe table name
arrayAssoziative array of fields to insert
stringbuildUpdate(string $tableName, array $fields, array $whereClauses) : string
String values in passed aFields and aWhere parameter will be escaped automatically.
Example:
$db = cRegistry::getDb();
$fields = array('code' => "... some new code n' fun ...");
$whereClauses = array('idcode' => 123);
$statement = $db->buildUpdate($cfg['tab']['code'], $fields, $whereClauses);
$db->query($statement);
stringThe table name
arrayAssoziative array of fields to update
arrayAssoziative array of field in where clause. Multiple entries will be concatenated with AND
stringclose()
| deprecated | 2012-10-02 This method is deprecated. Use disconnect instead. |
|---|
connect() : object | resource | int | null
objectresourceintnullConnection handler. Return value depends on
used driver and is null in case of an error.copyResultToArray($sTable)
| deprecated | [2011-03-03] This method is deprecated. Use toArray() instead. |
|---|
disconnect() : void
escape(string $string) : string
stringThe string to escape
stringEscaped stringf(mixed $name, mixed $default) : mixed
mixedThe field name or index position
mixedThe default value to return
mixedThe value of fieldfree() : int
intgetHaltBehaviour() : string
stringgetLastInsertedId(string $tableName) : int | null
string
intnulllast id of tablegetMetaData(string $tableName, bool $full) : array
stringThe table to get metadata or empty string to retrieve metadata of all tables
boolFlag to load full metadata
arrayDepends on used database and on parameter $fullgetProfileData() : array
arrayProfile data array like:
- $arr[$i]['time'] (float) Elapsed time to execute the query
- $arr[$i]['query'] (string) The query itselfgetResultObject($className) : object
If optional param $className is set, the result object is an instance of class $className.
objectgetServerInfo() : array | null
The return value depends always on used DBMS.
arraynullAssoziative array as follows or null:
- $arr['description'] (string) Optional, server description
- $arr['version'] (string) Optional, server versiongetTableNames() : array | null
arraynullIndexed array containing assoziative table data as
follows or null:
- $info[$i]['table_name']
- $info[$i]['tablespace_name']
- $info[$i]['database']halt(string $message) : void
Error handler function, delegates passed message to the function reportHalt() if property $this->_haltBehaviour is not set to self::HALT_REPORT.
Terminates further script execution if $this->_haltBehaviour is set to self::HALT_YES
stringThe message to use for error handling
haltmsg($message)
| deprecated | 2012-10-02 This method is deprecated. Use reportHalt instead. |
|---|
insert(string $tableName, array $fields) : bool
String values in passed aFields parameter will be escaped automatically.
Example:
$db = cRegistry::getDb();
$fields = array(
'idcatart' => $idcatart,
'idlang' => $lang,
'idclient' => $client,
'code' => "... code n' fun ...",
);
$result = $db->insert($cfg['tab']['code'], $fields);
stringThe table name
arrayAssoziative array of fields to insert
boolisProfilingEnabled() : bool
boolloadDriver() : void
\cDbException |
|---|
nextRecord() : bool
boolnf()
| deprecated | 2012-10-02 This method is deprecated. Use numRows instead. |
|---|
np()
| deprecated | 2012-10-02 This method is not longer supported. |
|---|
numFields() : int
intNumber of fieldsnumRows() : int
intThe number of rows from last select query resultp($name)
| deprecated | 2012-10-02 This method is not longer supported. |
|---|
prepare(string $statement) : string
Accepts multiple parameter, where the first parameter should be the query and any additional parameter should be the values to replace in format definitions. As an alternative the second parameter cound be also a indexed array with values to replace in format definitions.
Other option is to call this function with the statement containing named parameter and the second parameter as a assoziative array with key/value pairs to set in statement.
Examples:
// multiple parameter
$sql = $obj->prepare('SELECT * FROM `%s` WHERE id = %d', 'tablename', 123);
// 2 parameter where the first is the statement with formatting signs and the second the entries array
$sql = $obj->prepare('SELECT * FROM `%s` WHERE id = %d', array('tablename', 123));
// 2 parameter where the first is the statement with named parameter and the second the assoziative entries array
$sql = $obj->prepare('SELECT * FROM `:mytab` WHERE id = :myid', array('mytab' => 'tablename', 'myid' => 123));
stringThe sql statement to prepare.
\Exception |
If statement is empty or function is called with less than 2 parameters |
|---|
stringThe prepared sql statementquery(string $statement) : resource | int | object | bool
If called with one parameter, it executes the statement directly.
Accepts multiple parameter, where the first parameter should be the query and any additional parameter should be the values to replace in format definitions. As an alternative the second parameter cound be also a indexed array with values to replace in format definitions.
Other option is to call this function with the statement containing named parameter and the second parameter as a assoziative array with key/value pairs to set in statement.
Examples:
// call with one parameter
$obj->query('SELECT * FROM `tablename` WHERE id = 123');
// call with multiple parameter
$obj->query('SELECT * FROM `%s` WHERE id = %d', 'tablename', 123);
// 2 parameter where the first is the statement with formatting signs and the second the entries array
$obj->query('SELECT * FROM `%s` WHERE id = %d', array('tablename', 123));
// 2 parameter where the first is the statement with named parameter and the second the assoziative entries array
$obj->query('SELECT * FROM `:mytab` WHERE id = :myid', array('mytab' => 'tablename', 'myid' => 123));
stringThe SQL statement to execute.
resourceintobjectboolDepends on used database driver, false on errorreportHalt(string $message) : void
Concatenates a detailed error message and invoke PHP's error_log() method.
string
seek($pos) : void
server_info()
| deprecated | 2012-10-02 This method is deprecated. Use getTableNames instead. |
|---|
setDefaultConfiguration(array $defaultDbCfg) : void
array
table_names()
| deprecated | 2012-10-02 This method is deprecated. Use getTableNames instead. |
|---|
toArray(string $fetchMode) : array
stringOne of cDbDriverHandler::FETCH_* constants
arrayupdate(string $tableName, array $fields, array $whereClauses) : bool
String values in passed fields and whereClauses parameter will be escaped automatically.
Example:
$db = cRegistry::getDb();
$fields = array('code' => "... some new code n' fun ...");
$whereClauses = array('idcode' => 123);
$result = $db->update($cfg['tab']['code'], $fields, $whereClauses);
stringThe table name
arrayAssoziative array of fields to update
arrayAssoziative array of field in where clause. Multiple entries will be concatenated with AND
bool_addProfileData(float $timeStart, float $timeEnd, string $statement) : void
float
float
string
_getConnection(mixed $data) : mixed
mixedConnection data array or variable
mixedEither The connection (object, resource, integer) or null_prepareStatement(string $statement, array $arguments) : string
string
array
string_prepareStatementA(string $statement, array $arguments) : string
Examples:
// named parameter and assoziative entries array
$sql = $obj->_prepareStatementA('SELECT * FROM `:mytab` WHERE id = :myid', array('mytab' => 'tablename', 'myid' => 123));
$sql = $obj->_prepareStatementA('SELECT * FROM `:mytab` WHERE id = :myid AND user = :myuser', array('mytab' => 'tablename', 'myid' => 123, 'myuser' => 3));
string
arrayArguments array containing the query with named parameter and assoziative entries array
string_prepareStatementF(string $statement, array $arguments) : string
Examples:
$obj->_prepareStatementF('SELECT * FROM `%s` WHERE id = %d', 'tablename', 123);
$obj->_prepareStatementF('SELECT * FROM `%s` WHERE id = %d AND user = %d', 'tablename', 123, 3);
string
arrayArguments array containing the query with formatting signs and the entries.
string_removeConnection(mixed $connection) : void
mixedThe connection to remove in cache
_setConnection(mixed $data, mixed $connection) : void
mixedConnection data array
mixedThe connection to store in cache
$_connectionCache
| array |
|---|
$_dbCfg : array
$_defaultDbCfg : array
$_driver : \cDbDriverAbstract
$_driverType : string
$_haltBehaviour : string
Feasible values are - "yes" (halt with message) - "no" (ignore errors quietly) - "report" (ignore errror, but spit a warning)
$_haltMsgPrefix : string
$_profileData : array
FETCH_ASSOC
FETCH_BOTH
FETCH_NUMERIC
HALT_NO
HALT_REPORT
HALT_YES