Methods summary
public
|
#
__construct( array $options = array() )
Constructor, sets passed options and connects to the DBMS, if not done
before.
Constructor, sets passed options and connects to the DBMS, if not done
before.
Uses default connection settings, passed $options['connection'] settings will
overwrite connection settings for current instance.
Parameters
- $options
array $options 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
|
public
boolean
|
#
isProfilingEnabled( )
Checks if profiling was enabled via configuration.
Checks if profiling was enabled via configuration.
Returns
boolean
|
public
string
|
#
getHaltBehaviour( )
Returns the halt behaviour setting.
Returns the halt behaviour setting.
Returns
string
|
public
|
#
loadDriver( )
Loads the database driver and checks its base functionality.
Loads the database driver and checks its base functionality.
Throws
|
public
cDbDriverAbstract
|
#
getDriver( )
Returns the database driver instance.
Returns the database driver instance.
Returns
|
public static
|
#
setDefaultConfiguration( array $defaultDbCfg )
Setter for default database configuration, the connection values.
Setter for default database configuration, the connection values.
Parameters
- $defaultDbCfg
array $defaultDbCfg
|
protected
mixed
|
#
_getConnection( mixed $data )
Returns connection from connection cache
Returns connection from connection cache
Parameters
- $data
mixed $data Connection data array or variable
Returns
mixed Either The connection (object, resource, integer) or null
|
protected
|
#
_setConnection( mixed $data, mixed $connection )
Stores connection in connection cache
Stores connection in connection cache
Parameters
- $data
mixed $data Connection data array
- $connection
mixed $connection The connection to store in cache
|
protected
|
#
_removeConnection( mixed $connection )
Removes connection from cache
Removes connection from cache
Parameters
- $connection
mixed $connection The connection to remove in cache
|
protected static
|
#
_addProfileData( float $timeStart, float $timeEnd, string $statement )
Adds a entry to the profile data.
Adds a entry to the profile data.
Parameters
- $timeStart
float $timeStart
- $timeEnd
float $timeEnd
- $statement
string $statement
|
public static
array
|
#
getProfileData( )
Returns collected profile data.
Returns collected profile data.
Returns
array Profile data array like: - $arr[$i]['time'] (float) Elapsed time to execute the
query - $arr[$i]['query'] (string) The query itself
|
public
string
|
#
prepare( string $statement )
Prepares the statement for execution and returns it back. 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.
Prepares the statement for execution and returns it back. 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));
Parameters
- $statement
string $statement The sql statement to prepare.
Returns
string The prepared sql statement
Throws
Exception If statement is empty or function is called with less than 2 parameters
|
protected
string
|
#
_prepareStatement( string $statement, array $arguments )
Prepares the passed statement.
Prepares the passed statement.
Parameters
- $statement
string $statement
- $arguments
array $arguments
Returns
string
|
protected
string
|
#
_prepareStatementF( string $statement, array $arguments )
Prepares a statement with parameter for execution.
Prepares a statement with parameter for execution.
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);
Parameters
- $statement
string $statement
- $arguments
array $arguments Arguments array containing the query with formatting signs and the
entries.
Returns
string
|
protected
string
|
#
_prepareStatementA( string $statement, array $arguments )
Prepares a statement with named parameter for execution.
Prepares a statement with named parameter for execution.
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));
Parameters
- $statement
string $statement
- $arguments
array $arguments Arguments array containing the query with named parameter and
assoziative entries array
Returns
string
|
public
object
|
#
connect( )
Establishes a connection to the database server.
Establishes a connection to the database server.
Returns
object resource int null value depends on used driver and is null in case of an error.
|
public
boolean
|
#
insert( string $tableName, array $fields )
Builds and executes a insert query. String values in passed aFields parameter
will be escaped automatically.
Builds and executes a insert query. String values in passed aFields parameter
will be escaped automatically.
Example:
$db = cRegistry::getDb();
$fields = array(
'idcatart' => $idcatart,
'idlang' => $lang,
'idclient' => $client,
'code' => "<html>... code n' fun ...</html>",
);
$result = $db->insert($cfg['tab']['code'], $fields);
Parameters
- $tableName
string $tableName The table name
- $fields
array $fields Assoziative array of fields to insert
Returns
boolean
|
public
string
|
#
buildInsert( string $tableName, array $fields )
Builds and returns a insert query. String values in passed fields parameter
will be escaped automatically.
Builds and returns a insert query. 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' => "<html>... code n' fun ...</html>",
);
$statement = $db->buildInsert($cfg['tab']['code'], $fields);
$db->query($statement);
Parameters
- $tableName
string $tableName The table name
- $fields
array $fields Assoziative array of fields to insert
Returns
string
|
public
boolean
|
#
update( string $tableName, array $fields, array $whereClauses )
Builds and executes a update query. String values in passed fields and
whereClauses parameter will be escaped automatically.
Builds and executes a update query. String values in passed fields and
whereClauses parameter will be escaped automatically.
Example:
$db = cRegistry::getDb();
$fields = array('code' => "<html>... some new code n' fun ...</html>");
$whereClauses = array('idcode' => 123);
$result = $db->update($cfg['tab']['code'], $fields, $whereClauses);
Parameters
- $tableName
string $tableName The table name
- $fields
array $fields Assoziative array of fields to update
- $whereClauses
array $whereClauses Assoziative array of field in where clause. Multiple entries will
be concatenated with AND
Returns
boolean
|
public
string
|
#
buildUpdate( string $tableName, array $fields, array $whereClauses )
Builds and returns a update query. String values in passed aFields and aWhere
parameter will be escaped automatically.
Builds and returns a update query. String values in passed aFields and aWhere
parameter will be escaped automatically.
Example:
$db = cRegistry::getDb();
$fields = array('code' => "<html>... some new code n' fun ...</html>");
$whereClauses = array('idcode' => 123);
$statement = $db->buildUpdate($cfg['tab']['code'], $fields,
$whereClauses);
$db->query($statement);
Parameters
- $tableName
string $tableName The table name
- $fields
array $fields Assoziative array of fields to update
- $whereClauses
array $whereClauses Assoziative array of field in where clause. Multiple entries will
be concatenated with AND
Returns
string
|
public
resource
|
#
query( string $statement )
Executes the statement. If called with one parameter, it executes the
statement directly.
Executes the statement. 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));
Parameters
- $statement
string $statement The SQL statement to execute.
Returns
resource int object bool database driver, false on error
|
public
boolean
|
#
nextRecord( )
Fetches the next record set from result set
Fetches the next record set from result set
Returns
boolean
|
public
object
|
#
getResultObject( mixed $className = NULL )
This method returns the current result set as object or null if no result set
is left. If optional param $className is set, the result object is an instance
of class $className.
This method returns the current result set as object or null if no result set
is left. If optional param $className is set, the result object is an instance
of class $className.
Returns
object
|
public
integer
|
#
affectedRows( )
Returns number of affected rows from last executed query (update, delete)
Returns number of affected rows from last executed query (update, delete)
Returns
integer Number of affected rows
|
public
integer
|
#
numRows( )
Returns the number of rows from last executed select query.
Returns the number of rows from last executed select query.
Returns
integer The number of rows from last select query result
|
public
integer
|
#
numFields( )
Returns the number of fields (columns) from current record set
Returns the number of fields (columns) from current record set
Returns
integer Number of fields
|
public
integer
|
#
free( )
Discard the query result
Returns
integer
|
public
string
|
#
escape( string $string )
Escape string for using in SQL-Statement.
Escape string for using in SQL-Statement.
Parameters
- $string
string $string The string to escape
Returns
string Escaped string
|
public
|
#
seek( integer $pos )
Moves the cursor (position inside current result sets).
Moves the cursor (position inside current result sets).
Parameters
- $pos
integer $iPos The positon to move to inside the current result set
|
public
integer
|
#
getLastInsertedId( string $tableName = '' )
Get last inserted id of given table name
Get last inserted id of given table name
Parameters
- $tableName
string $tableName
Returns
integer null id of table
|
public
array
|
#
getMetaData( string $tableName = '', boolean $full = false )
Parses te table structure and generates a metadata from it.
Parses te table structure and generates a metadata from it.
Parameters
- $tableName
string $tableName The table to get metadata or empty string to retrieve metadata of all
tables
- $full
boolean $full Flag to load full metadata
Returns
array Depends on used database and on parameter $full
|
public
array
|
#
getTableNames( )
Returns names of existing tables.
Returns names of existing tables.
Returns
array null array containing assoziative table data as follows or null: -
$info[$i]['table_name'] - $info[$i]['tablespace_name'] - $info[$i]['database']
|
public
array
|
#
getServerInfo( )
Returns information about DB server. The return value depends always on used
DBMS.
Returns information about DB server. The return value depends always on used
DBMS.
Returns
array null array as follows or null: - $arr['description'] (string) Optional, server
description - $arr['version'] (string) Optional, server version
|
public
|
#
disconnect( )
Closes the connection and frees the query id.
Closes the connection and frees the query id.
|
public
mixed
|
#
f( mixed $name, mixed $default = NULL )
Returns the desired field value from current record set.
Returns the desired field value from current record set.
Parameters
- $name
mixed $name The field name or index position
- $default
mixed $default The default value to return
Returns
mixed The value of field
|
public
array
|
#
toArray( string $fetchMode = cDbDriverHandler::FETCH_ASSOC )
Returns current record set as a associative and/or indexed array.
Returns current record set as a associative and/or indexed array.
Parameters
- $fetchMode
string $fetchMode One of cDbDriverHandler::FETCH_* constants
Returns
array
|
public
stdClass
|
#
toObject( )
Returns current record set as a object
Returns current record set as a object
Returns
stdClass
|
public
|
#
halt( string $message )
Error handling
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
Parameters
- $message
string $message The message to use for error handling
|
public
|
#
reportHalt( string $message )
Logs passed message, basically the last db error to the error log.
Concatenates a detailed error message and invoke PHP's error_log() method.
Logs passed message, basically the last db error to the error log.
Concatenates a detailed error message and invoke PHP's error_log() method.
Parameters
|
public
|
|
public
|
|
public
|
|
public
|
|