A class defining a database connection, and mechanisms for working with a database.
This library is largely compatible with adodb_lite with the pear,extended,transaction plugins with a few notable differences:
Differences:
We encourage you to not use sequence tables and use auto-increment fields instead.
package |
CMS |
---|---|
author |
Robert Campbell |
copyright |
Copyright (c) 2015, Robert Campbell calguy1000@cmsmadesimple.org |
since | 2.2 |
property-read |
The total query time so far in this request (in seconds) |
property-read |
The total number of queries executed so far. |
__construct(\CMSMS\Database\ConnectionSpec $spec)
NewDataDictionary() : \CMSMS\Database\DataDictionary
Data Dictionary objects are used for manipulating tables, i.e: creating, altering and editing them.
DbType() : string
string
Connect() : boolean
boolean
Success or failure
Disconnect()
IsConnected() : boolean
boolean
Close()
QMagic(string $str) : string
This method is now just a deprecated alias for the qstr flag as we now require magic quotes to be disabled.
string
$str string
qstr(string $str) : string
Warning: This method may require two way traffic with the database depending upon the database.
string
$str string
concat() : string
This function accepts a variable number of string arguments.
string
IfNull(string $field, string $ifNull) : string
string
$fieldThe field to test
string
$ifNullThe value to use if $field is null.
string
Affected_Rows() : integer
integer
Insert_ID() : integer
integer
Prepare(string $sql) : \CMSMS\Database\Statement
SelectLimit(string $sql, integer $nrows = -1, integer $offset = -1, $inputarr = null) : \CMSMS\Database\ResultSet
string
$sqlinteger
$nrowsThe number of rows to return
integer
$offsetThe starting offset of rows to return
$inputarr \CMSMS\Database\ResultSet
Execute(string $sql, array $inputarr = null) : \CMSMS\Database\ResultSet
string
$sqlThe SQL statement to execute.
array
$inputarrAny parameters marked as placeholders in the SQL statement.
\CMSMS\Database\ResultSet
GetArray(string $sql, array $inputarr = null) : array
string
$sqlThe SQL statement to execute.
array
$inputarrAny parameters marked as placeholders in the SQL statement.
array
An associative array of matched results.
GetAll(string $sql, array $inputarr = null) : array
string
$sqlThe SQL statement to execute.
array
$inputarrAny parameters marked as placeholders in the SQL statement.
array
GetAssoc(string $sql, array $inputarr = null, boolean $force_array = false, boolean $first2cols = false)
string
$sqlThe SQL statement to execute
array
$inputarrAny parameters marked as placeholders in the SQL statement.
boolean
$force_arrayForce each element of the output to be an associative array.
boolean
$first2colsOnly output the first 2 columns in an associative array. Does not work with force_array.
GetCol(string $sql, array $inputarr = null, boolean $trim = false) : array
string
$sqlThe SQL statement to execute.
array
$inputarrAny parameters marked as placeholders in the SQL statement.
boolean
$trimOptionally trim the output results.
array
A single flat array of results, one entry per row matched.
GetRow(string $sql, array $inputarr = null) : array
string
$sqlThe SQL statement to execute.
array
$inputarrAny parameters marked as placeholders in the SQL statement.
array
An associative array representing a single resultset row.
GetOne(string $sql, array $inputarr = null) : mixed
string
$sqlThe SQL statement to execute.
array
$inputarrAny parameters marked as placeholders in the SQL statement.
mixed
BeginTrans()
StartTrans()
CompleteTrans()
This method will either do a rollback or a commit depending upon if errors have been detected.
CommitTrans(boolean $ok = true)
boolean
$okIndicates wether there is success or not.
RollbackTrans()
FailTrans()
HasFailedTrans() : boolean
boolean
GenID(string $seqname) : integer
This function will not automatically create the sequence table if not specified.
string
$seqnameThe name of the sequence table.
integer
CreateSequence(string $seqname, integer $startID) : boolean
string
$seqnamethe name of the sequence table.
integer
$startID boolean
DropSequence(string $seqname) : boolean
string
$seqnameThe name of the sequence table.
boolean
DBTimeStamp(integer $timestamp) : string
integer
$timestamp string
UnixTimeStamp(string $str) : integer
string
$str integer
DBDate(mixed $date) : string
mixed
$dateEither a string date, or an integer timestamp
string
UnixDate() : integer
integer
Time() : integer
integer
Date() : integer
integer
ErrorMsg() : string
string
ErrorNo() : integer
integer
SetErrorHandler(callable $fn = null)
callable
$fnSetDebugMode(boolean $flag = true, callable $debug_handler = null)
boolean
$flagEnable or Disable debug mode.
callable
$debug_handlerSetDebugCallback(callable $debug_handler = null)
callable
$debug_handlerInitialize(\CMSMS\Database\Connectionspec $spec) : \CMSMS\Database\Connection
This is the preferred wa to open a new database connection.
\CMSMS\Database\Connectionspec
$specAn object describing the database to connect to.
ERROR_CONNECT
ERROR_EXECUTE
ERROR_TRANSACTION
ERROR_DATADICT
query_time_total : float
The total query time so far in this request (in seconds)
float
query_count : integer
The total number of queries executed so far.
integer