This class contains functions for handling record sets and interaction with database in CONTENIDO.
package |
Core |
subpackage |
Database |
Methods
Constructor, sets passed options and connects to the DBMS, if not done before.
__construct(array $options) : void
Inherited
Uses default connection settings, passed $options['connection'] settings
will overwrite connection settings for current instance.
inherited_from |
\cDbDriverHandler::__construct() |
Parameters
$options
array
Assoziative 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
Magic getter function for old class variables.
__get(string $name) : mixed
Inherited
inherited_from |
\cDbDriverHandler::__get() |
Parameters
$name
string
name of the variable
Returns
mixed
Returns number of affected rows from last executed query (update, delete)
affectedRows() : int
Inherited
inherited_from |
\cDbDriverHandler::affectedRows() |
Returns
int
Number of affected rows
affected_rows()
affected_rows()
Inherited
Builds and returns a insert query.
buildInsert(string $tableName, array $fields) : string
Inherited
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);
inherited_from |
\cDbDriverHandler::buildInsert() |
Parameters
$tableName
string
The table name
$fields
array
Assoziative array of fields to insert
Returns
string
Builds and returns a update query.
buildUpdate(string $tableName, array $fields, array $whereClauses) : string
Inherited
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);
inherited_from |
\cDbDriverHandler::buildUpdate() |
Parameters
$tableName
string
The table name
$fields
array
Assoziative array of fields to update
$whereClauses
array
Assoziative array of field in where clause.
Multiple entries will be concatenated with AND
Returns
string
close()
close()
Inherited
inherited_from |
\cDbDriverHandler::close() |
Establishes a connection to the database server.
connect() : object | resource | int | null
Inherited
inherited_from |
\cDbDriverHandler::connect() |
Returns
object
resource
int
null
Connection handler. Return value depends on
used driver and is null in case of an error.
copyResultToArray()
copyResultToArray($sTable)
Inherited
inherited_from |
\cDbDriverHandler::copyResultToArray() |
Parameters
$sTable
Closes the connection and frees the query id.
disconnect() : void
Inherited
inherited_from |
\cDbDriverHandler::disconnect() |
Escape string for using in SQL-Statement.
escape(string $string) : string
Inherited
inherited_from |
\cDbDriverHandler::escape() |
Parameters
$string
string
The string to escape
Returns
string
Escaped string
Returns the desired field value from current record set.
f(mixed $name, mixed $default) : mixed
Inherited
inherited_from |
\cDbDriverHandler::f() |
Parameters
$name
mixed
The field name or index position
$default
mixed
The default value to return
Returns
mixed
The value of field
Discard the query result
free() : int
Inherited
inherited_from |
\cDbDriverHandler::free() |
Returns
int
Returns the database driver instance.
getDriver() : \cDbDriverAbstract
Inherited
inherited_from |
\cDbDriverHandler::getDriver() |
Returns
Returns error message of last occurred error from database.
getErrorMessage() : string
Returns
string
database error message
Returns error code of last occurred error from database.
getErrorNumber() : int
Returns
int
database error code
Returns the halt behaviour setting.
getHaltBehaviour() : string
Inherited
inherited_from |
\cDbDriverHandler::getHaltBehaviour() |
Returns
string
Get last inserted id of given table name
getLastInsertedId(string $tableName) : int | null
Inherited
inherited_from |
\cDbDriverHandler::getLastInsertedId() |
Parameters
$tableName
string
Returns
int
null
last id of table
Returns the link ID resource.
getLinkId() : null | resource
Returns collected profile data.
getProfileData() : array
InheritedStatic
inherited_from |
\cDbDriverHandler::getProfileData() |
Returns
array
Profile data array like:
- $arr[$i]['time'] (float) Elapsed time to execute the query
- $arr[$i]['query'] (string) The query itself
Returns the query ID resource.
getQueryId() : null | resource
Returns the current record data.
getRecord() : array
This method returns the current result set as object or null if no result set is left.
getResultObject($className) : object
Inherited
If optional param $className is set, the result object is an instance of class
$className.
inherited_from |
\cDbDriverHandler::getResultObject() |
Parameters
$className
Returns
object
Return the current row count.
getRow() : int
Returns information about DB server.
getServerInfo() : array | null
Inherited
The return value depends always on
used DBMS.
inherited_from |
\cDbDriverHandler::getServerInfo() |
Returns
array
null
Assoziative array as follows or null:
- $arr['description'] (string) Optional, server description
- $arr['version'] (string) Optional, server version
Returns names of existing tables.
getTableNames() : array | null
Inherited
inherited_from |
\cDbDriverHandler::getTableNames() |
Returns
array
null
Indexed array containing assoziative table data as
follows or null:
- $info[$i]['table_name']
- $info[$i]['tablespace_name']
- $info[$i]['database']
Error handling
halt(string $message) : void
Inherited
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
inherited_from |
\cDbDriverHandler::halt() |
Parameters
$message
string
The message to use for error handling
haltmsg()
haltmsg($message)
Inherited
inherited_from |
\cDbDriverHandler::haltmsg() |
Parameters
$message
Increments current row count by 1.
incrementRow() : void
Do not set it manually unless you know what you are doing.
Builds and executes a insert query.
insert(string $tableName, array $fields) : bool
Inherited
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);
inherited_from |
\cDbDriverHandler::insert() |
Parameters
$tableName
string
The table name
$fields
array
Assoziative array of fields to insert
Returns
bool
Checks if profiling was enabled via configuration.
isProfilingEnabled() : bool
Inherited
inherited_from |
\cDbDriverHandler::isProfilingEnabled() |
Returns
bool
Loads the database driver and checks its base functionality.
loadDriver() : void
Inherited
inherited_from |
\cDbDriverHandler::loadDriver() |
Exceptions
Fetches the next record set from result set
nextRecord() : bool
Inherited
inherited_from |
\cDbDriverHandler::nextRecord() |
Returns
bool
next_record()
next_record()
Inherited
nf()
nf()
Inherited
inherited_from |
\cDbDriverHandler::nf() |
np()
np()
Inherited
inherited_from |
\cDbDriverHandler::np() |
Returns the number of fields (columns) from current record set
numFields() : int
Inherited
inherited_from |
\cDbDriverHandler::numFields() |
Returns
int
Number of fields
Returns the number of rows from last executed select query.
numRows() : int
Inherited
inherited_from |
\cDbDriverHandler::numRows() |
Returns
int
The number of rows from last select query result
num_fields()
num_fields()
Inherited
num_rows()
num_rows()
Inherited
p()
p($name)
Inherited
inherited_from |
\cDbDriverHandler::p() |
Parameters
$name
Prepares the statement for execution and returns it back.
prepare(string $statement) : string
Inherited
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));
inherited_from |
\cDbDriverHandler::prepare() |
Parameters
$statement
string
The sql statement to prepare.
Exceptions
\Exception |
If statement is empty or function is called with less than 2 parameters |
Returns
string
The prepared sql statement
Executes the statement.
query(string $statement) : resource | int | object | bool
Inherited
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));
inherited_from |
\cDbDriverHandler::query() |
Parameters
$statement
string
The SQL statement to execute.
Returns
resource
int
object
bool
Depends on used database driver, false on error
Logs passed message, basically the last db error to the error log.
reportHalt(string $message) : void
Inherited
Concatenates a detailed error message and invoke PHP's error_log() method.
inherited_from |
\cDbDriverHandler::reportHalt() |
Parameters
$message
string
Moves the cursor (position inside current result sets).
seek($pos) : void
Inherited
inherited_from |
\cDbDriverHandler::seek() |
Parameters
$pos
server_info()
server_info()
Inherited
inherited_from |
\cDbDriverHandler::server_info() |
Setter for default database configuration, the connection values.
setDefaultConfiguration(array $defaultDbCfg) : void
InheritedStatic
inherited_from |
\cDbDriverHandler::setDefaultConfiguration() |
Parameters
$defaultDbCfg
array
Sets the current error message from database.
setErrorMessage(string $errorMessage) : void
Parameters
$errorMessage
string
current error message
Sets the current error number from database.
setErrorNumber(int $errorNumber) : void
Parameters
$errorNumber
int
current error number
Sets the link ID resource.
setLinkId(resource $linkId) : void
Do not set it manually unless you know what you are doing.
Parameters
$linkId
resource
link ID resource
Sets the query ID resource.
setQueryId($queryId) : void
Do not set it manually unless you know what you are doing.
Parameters
$queryId
resource query ID resource
Sets the current record data set.
setRecord(array $record) : void
Do not set it manually unless you know what you are doing.
Parameters
$record
array
current record set data
Sets the current row count.
setRow(int $row) : void
Do not set it manually unless you know what you are doing.
Parameters
$row
int
current row count
table_names()
table_names()
Inherited
inherited_from |
\cDbDriverHandler::table_names() |
Returns current record set as a associative and/or indexed array.
toArray(string $fetchMode) : array
Inherited
inherited_from |
\cDbDriverHandler::toArray() |
Parameters
$fetchMode
string
One of cDbDriverHandler::FETCH_* constants
Returns
array
Returns current record set as a object
toObject() : \stdClass
Inherited
inherited_from |
\cDbDriverHandler::toObject() |
Returns
Builds and executes a update query.
update(string $tableName, array $fields, array $whereClauses) : bool
Inherited
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);
inherited_from |
\cDbDriverHandler::update() |
Parameters
$tableName
string
The table name
$fields
array
Assoziative array of fields to update
$whereClauses
array
Assoziative array of field in where clause.
Multiple entries will be concatenated with AND
Returns
bool
Adds a entry to the profile data.
_addProfileData(float $timeStart, float $timeEnd, string $statement) : void
InheritedStatic
inherited_from |
\cDbDriverHandler::_addProfileData() |
Parameters
$timeStart
float
$timeEnd
float
$statement
string
Returns connection from connection cache
_getConnection(mixed $data) : mixed
Inherited
inherited_from |
\cDbDriverHandler::_getConnection() |
Parameters
$data
mixed
Connection data array or variable
Returns
mixed
Either The connection (object, resource, integer) or null
Prepares the passed statement.
_prepareStatement(string $statement, array $arguments) : string
Inherited
inherited_from |
\cDbDriverHandler::_prepareStatement() |
Parameters
$statement
string
$arguments
array
Returns
string
Prepares a statement with named parameter for execution.
_prepareStatementA(string $statement, array $arguments) : string
Inherited
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));
inherited_from |
\cDbDriverHandler::_prepareStatementA() |
Parameters
$statement
string
$arguments
array
Arguments array containing the query with named parameter and assoziative entries array
Returns
string
Prepares a statement with parameter for execution.
_prepareStatementF(string $statement, array $arguments) : string
Inherited
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);
inherited_from |
\cDbDriverHandler::_prepareStatementF() |
Parameters
$statement
string
$arguments
array
Arguments array containing the query with formatting
signs and the entries.
Returns
string
Removes connection from cache
_removeConnection(mixed $connection) : void
Inherited
inherited_from |
\cDbDriverHandler::_removeConnection() |
Parameters
$connection
mixed
The connection to remove in cache
Stores connection in connection cache
_setConnection(mixed $data, mixed $connection) : void
Inherited
inherited_from |
\cDbDriverHandler::_setConnection() |
Parameters
$data
mixed
Connection data array
$connection
mixed
The connection to store in cache
Properties
$_connectionCache
Inherited
array |
|
inherited_from |
\cDbDriverHandler::$$_connectionCache |
$_dbCfg : array
Inherited
inherited_from |
\cDbDriverHandler::$$_dbCfg |
$_defaultDbCfg : array
Inherited
inherited_from |
\cDbDriverHandler::$$_defaultDbCfg |
$_driverType : string
Inherited
inherited_from |
\cDbDriverHandler::$$_driverType |
$_haltBehaviour : string
Inherited
Feasible values are
- "yes" (halt with message)
- "no" (ignore errors quietly)
- "report" (ignore errror, but spit a warning)
inherited_from |
\cDbDriverHandler::$$_haltBehaviour |
$_haltMsgPrefix : string
Inherited
inherited_from |
\cDbDriverHandler::$$_haltMsgPrefix |
$_profileData : array
Inherited
inherited_from |
\cDbDriverHandler::$$_profileData |
Constants
FETCH_ASSOC
FETCH_ASSOC
Inherited
inherited_from |
\cDbDriverHandler::FETCH_ASSOC |
FETCH_BOTH
FETCH_BOTH
Inherited
inherited_from |
\cDbDriverHandler::FETCH_BOTH |
FETCH_NUMERIC
FETCH_NUMERIC
Inherited
inherited_from |
\cDbDriverHandler::FETCH_NUMERIC |
HALT_NO
HALT_NO
Inherited
inherited_from |
\cDbDriverHandler::HALT_NO |
HALT_REPORT
HALT_REPORT
Inherited
inherited_from |
\cDbDriverHandler::HALT_REPORT |
HALT_YES
HALT_YES
Inherited
inherited_from |
\cDbDriverHandler::HALT_YES |