Connection
    
            
            in package
            
        
    
    
    
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:
- GenID will not automatically create a sequence table.
   
We encourage you to not use sequence tables and use auto-increment fields instead.
 
Tags
Table of Contents
Constants
- ERROR_CONNECT = 'CONNECT'
 - This constant defines an error with connecting to the database.
 - ERROR_DATADICT = 'DATADICTIONARY'
 - This constant defines an error in a datadictionary command.
 - ERROR_EXECUTE = 'EXECUTE'
 - This constant defines an error with an execute statement.
 - ERROR_TRANSACTION = 'TRANSACTION'
 - This constant defines an error with a transaction.
 
Properties
- $query_count : int
 - $query_time_total : float
 
Methods
- __construct() : mixed
 - Construct a new Connection.
 - Affected_Rows() : int
 - Output the number of rows affected by the last query.
 - BeginTrans() : mixed
 - Begin a transaction
 - Close() : mixed
 - An alias for Disconnect.
 - CommitTrans() : mixed
 - Commit a simple transaction.
 - CompleteTrans() : mixed
 - Complete a smart transaction.
 - concat() : string
 - output the mysql expression for a string concatenation.
 - Connect() : bool
 - Open the database connection.
 - CreateSequence() : bool
 - Create a new sequence table.
 - Date() : int
 - An Alias for the UnixDate method.
 - DBDate() : string
 - Convert a date into something that is suitable for writing to a database.
 - DBTimeStamp() : string
 - A utility method to convert a unix timestamp into a database specific string suitable for use in queries.
 - DbType() : string
 - Return the database type.
 - Disconnect() : mixed
 - Close the database connection.
 - DropSequence() : bool
 - Drop a sequence table
 - ErrorMsg() : string
 - Return a string describing the latest error (if any)
 - ErrorNo() : int
 - Return the latest error number (if any)
 - Execute() : ResultSet
 - Execute an SQL Command
 - FailTrans() : mixed
 - Mark a transaction as failed.
 - GenID() : int
 - For use with sequence tables, this method will generate a new ID value.
 - GetAll() : array<string|int, mixed>
 - An alias for the GetArray method.
 - GetArray() : array<string|int, mixed>
 - Execute an SQL Commmand and return all of the results as an array.
 - GetAssoc() : mixed
 - A method to return an associative array.
 - GetCol() : array<string|int, mixed>
 - Execute an SQL statement that returns one column, and return all of the matches as an array.
 - GetOne() : mixed
 - Execute an SQL statement and return a single value.
 - GetRow() : array<string|int, mixed>
 - Exeute an SQL statement that returns one row of results, and return that row as an associative array.
 - HasFailedTrans() : bool
 - Test if a transaction has failed.
 - IfNull() : string
 - Output the mysql expression to test if an item is null.
 - Initialize() : Connection
 - Create a new database connection object.
 - Insert_ID() : int
 - Return the numeric ID of the last insert query into a table with an auto-increment field.
 - IsConnected() : bool
 - Test if the connection object is connected to the database.
 - NewDataDictionary() : DataDictionary
 - Create a new data dictionary object.
 - Prepare() : Statement
 - Create a prepared statement object.
 - QMagic() : string
 - Quote a string magically using the magic quotes flag.
 - qstr() : string
 - Quote a string in a database agnostic manner.
 - RollbackTrans() : mixed
 - Roll back a simple transaction.
 - SelectLimit() : ResultSet
 - Execute an SQL Select and limit the output.
 - SetDebugCallback() : mixed
 - Set the debug callback.
 - SetDebugMode() : mixed
 - Toggle debug mode.
 - SetErrorHandler() : mixed
 - Set an error handler function
 - StartTrans() : mixed
 - Begin a smart transaction
 - Time() : int
 - An alias for the UnixTimestamp method.
 - UnixDate() : int
 - Generate a unix timestamp representing the current date at midnight.
 - UnixTimeStamp() : int
 - A convenience method for converting a database specific string representing a date and time into a unix timestamp.
 
Constants
ERROR_CONNECT
This constant defines an error with connecting to the database.
    public
        mixed
    ERROR_CONNECT
    = 'CONNECT'
    
    
    
    
ERROR_DATADICT
This constant defines an error in a datadictionary command.
    public
        mixed
    ERROR_DATADICT
    = 'DATADICTIONARY'
    
    
    
    
ERROR_EXECUTE
This constant defines an error with an execute statement.
    public
        mixed
    ERROR_EXECUTE
    = 'EXECUTE'
    
    
    
    
ERROR_TRANSACTION
This constant defines an error with a transaction.
    public
        mixed
    ERROR_TRANSACTION
    = 'TRANSACTION'
    
    
    
    
Properties
$query_count read-only
    public
        int
    $query_count
    
        The total number of queries executed so far.
$query_time_total read-only
    public
        float
    $query_time_total
    
        The total query time so far in this request (in seconds)
Methods
__construct()
Construct a new Connection.
    public
                    __construct(ConnectionSpec $spec) : mixed
    Parameters
- $spec : ConnectionSpec
 
Affected_Rows()
Output the number of rows affected by the last query.
    public
    abstract                Affected_Rows() : int
    Return values
intBeginTrans()
Begin a transaction
    public
    abstract                BeginTrans() : mixed
    Close()
An alias for Disconnect.
    public
        final            Close() : mixed
    CommitTrans()
Commit a simple transaction.
    public
    abstract                CommitTrans([bool $ok = true ]) : mixed
    Parameters
- $ok : bool = true
 - 
                    
Indicates wether there is success or not.
 
CompleteTrans()
Complete a smart transaction.
    public
    abstract                CompleteTrans([bool $autoComplete = true ]) : mixed
    This method will either do a rollback or a commit depending upon if errors have been detected.
Parameters
- $autoComplete : bool = true
 - 
                    
If no errors have been detected attempt to auto commit the transaction.
 
concat()
output the mysql expression for a string concatenation.
    public
    abstract                concat() : string
    This function accepts a variable number of string arguments.
Return values
stringConnect()
Open the database connection.
    public
    abstract                Connect() : bool
    Return values
bool —Success or failure
CreateSequence()
Create a new sequence table.
    public
    abstract                CreateSequence(string $seqname[, int $startID = 0 ]) : bool
    Parameters
- $seqname : string
 - 
                    
the name of the sequence table.
 - $startID : int = 0
 
Return values
boolDate()
An Alias for the UnixDate method.
    public
                    Date() : int
    Return values
intDBDate()
Convert a date into something that is suitable for writing to a database.
    public
                    DBDate(mixed $date) : string
    Parameters
- $date : mixed
 - 
                    
Either a string date, or an integer timestamp
 
Return values
string —single-quoted localized date or 'null'
DBTimeStamp()
A utility method to convert a unix timestamp into a database specific string suitable for use in queries.
    public
                    DBTimeStamp(int $timestamp) : string
    Parameters
- $timestamp : int
 
Return values
string —single-quoted date-time or 'null'
DbType()
Return the database type.
    public
    abstract                DbType() : string
    Return values
stringDisconnect()
Close the database connection.
    public
    abstract                Disconnect() : mixed
    DropSequence()
Drop a sequence table
    public
    abstract                DropSequence(string $seqname) : bool
    Parameters
- $seqname : string
 - 
                    
The name of the sequence table.
 
Return values
boolErrorMsg()
Return a string describing the latest error (if any)
    public
    abstract                ErrorMsg() : string
    Return values
stringErrorNo()
Return the latest error number (if any)
    public
    abstract                ErrorNo() : int
    Return values
intExecute()
Execute an SQL Command
    public
                    Execute(string $sql[, array<string|int, mixed> $inputarr = null ]) : ResultSet
    Parameters
- $sql : string
 - 
                    
The SQL statement to execute.
 - $inputarr : array<string|int, mixed> = null
 - 
                    
Any parameters marked as placeholders in the SQL statement.
 
Return values
ResultSetFailTrans()
Mark a transaction as failed.
    public
    abstract                FailTrans() : mixed
    GenID()
For use with sequence tables, this method will generate a new ID value.
    public
    abstract                GenID(string $seqname) : int
    This function will not automatically create the sequence table if not specified.
Parameters
- $seqname : string
 - 
                    
The name of the sequence table.
 
Return values
intGetAll()
An alias for the GetArray method.
    public
                    GetAll(string $sql[, array<string|int, mixed> $inputarr = null ]) : array<string|int, mixed>
    Parameters
- $sql : string
 - 
                    
The SQL statement to execute.
 - $inputarr : array<string|int, mixed> = null
 - 
                    
Any parameters marked as placeholders in the SQL statement.
 
Return values
array<string|int, mixed>GetArray()
Execute an SQL Commmand and return all of the results as an array.
    public
                    GetArray(string $sql[, array<string|int, mixed> $inputarr = null ]) : array<string|int, mixed>
    Parameters
- $sql : string
 - 
                    
The SQL statement to execute.
 - $inputarr : array<string|int, mixed> = null
 - 
                    
Any parameters marked as placeholders in the SQL statement.
 
Return values
array<string|int, mixed> —An associative array of matched results.
GetAssoc()
A method to return an associative array.
    public
                    GetAssoc(string $sql[, array<string|int, mixed> $inputarr = null ][, bool $force_array = false ][, bool $first2cols = false ]) : mixed
    Parameters
- $sql : string
 - 
                    
The SQL statement to execute
 - $inputarr : array<string|int, mixed> = null
 - 
                    
Any parameters marked as placeholders in the SQL statement.
 - $force_array : bool = false
 - 
                    
Force each element of the output to be an associative array.
 - $first2cols : bool = false
 - 
                    
Only output the first 2 columns in an associative array. Does not work with force_array.
 
Tags
GetCol()
Execute an SQL statement that returns one column, and return all of the matches as an array.
    public
                    GetCol(string $sql[, array<string|int, mixed> $inputarr = null ][, bool $trim = false ]) : array<string|int, mixed>
    Parameters
- $sql : string
 - 
                    
The SQL statement to execute.
 - $inputarr : array<string|int, mixed> = null
 - 
                    
Any parameters marked as placeholders in the SQL statement.
 - $trim : bool = false
 - 
                    
Optionally trim the output results.
 
Return values
array<string|int, mixed> —A single flat array of results, one entry per row matched.
GetOne()
Execute an SQL statement and return a single value.
    public
                    GetOne(string $sql[, array<string|int, mixed> $inputarr = null ]) : mixed
    Parameters
- $sql : string
 - 
                    
The SQL statement to execute.
 - $inputarr : array<string|int, mixed> = null
 - 
                    
Any parameters marked as placeholders in the SQL statement.
 
GetRow()
Exeute an SQL statement that returns one row of results, and return that row as an associative array.
    public
                    GetRow(string $sql[, array<string|int, mixed> $inputarr = null ]) : array<string|int, mixed>
    Parameters
- $sql : string
 - 
                    
The SQL statement to execute.
 - $inputarr : array<string|int, mixed> = null
 - 
                    
Any parameters marked as placeholders in the SQL statement.
 
Return values
array<string|int, mixed> —An associative array representing a single resultset row.
HasFailedTrans()
Test if a transaction has failed.
    public
    abstract                HasFailedTrans() : bool
    Return values
boolIfNull()
Output the mysql expression to test if an item is null.
    public
    abstract                IfNull(string $field, string $ifNull) : string
    Parameters
- $field : string
 - 
                    
The field to test
 - $ifNull : string
 - 
                    
The value to use if $field is null.
 
Return values
stringInitialize()
Create a new database connection object.
    public
            static        Initialize(Connectionspec $spec) : Connection
    This is the preferred wa to open a new database connection.
Parameters
- $spec : Connectionspec
 - 
                    
An object describing the database to connect to.
 
Tags
Return values
ConnectionInsert_ID()
Return the numeric ID of the last insert query into a table with an auto-increment field.
    public
    abstract                Insert_ID() : int
    Return values
intIsConnected()
Test if the connection object is connected to the database.
    public
    abstract                IsConnected() : bool
    Return values
boolNewDataDictionary()
Create a new data dictionary object.
    public
    abstract            &    NewDataDictionary() : DataDictionary
    Data Dictionary objects are used for manipulating tables, i.e: creating, altering and editing them.
Return values
DataDictionaryPrepare()
Create a prepared statement object.
    public
    abstract                Prepare(string $sql) : Statement
    Parameters
- $sql : string
 - 
                    
The SQL query
 
Return values
StatementQMagic()
Quote a string magically using the magic quotes flag.
    public
                    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.
Parameters
- $str : string
 
Return values
stringqstr()
Quote a string in a database agnostic manner.
    public
    abstract                qstr(string $str) : string
    Warning: This method may require two way traffic with the database depending upon the database.
Parameters
- $str : string
 
Return values
stringRollbackTrans()
Roll back a simple transaction.
    public
    abstract                RollbackTrans() : mixed
    SelectLimit()
Execute an SQL Select and limit the output.
    public
                    SelectLimit(string $sql[, int $nrows = -1 ][, int $offset = -1 ][, mixed $inputarr = null ]) : ResultSet
    Parameters
- $sql : string
 - $nrows : int = -1
 - 
                    
The number of rows to return
 - $offset : int = -1
 - 
                    
The starting offset of rows to return
 - $inputarr : mixed = null
 
Return values
ResultSetSetDebugCallback()
Set the debug callback.
    public
                    SetDebugCallback([callable $debug_handler = null ]) : mixed
    Parameters
- $debug_handler : callable = null
 
SetDebugMode()
Toggle debug mode.
    public
                    SetDebugMode([bool $flag = true ][, callable $debug_handler = null ]) : mixed
    Parameters
- $flag : bool = true
 - 
                    
Enable or Disable debug mode.
 - $debug_handler : callable = null
 
SetErrorHandler()
Set an error handler function
    public
                    SetErrorHandler([callable $fn = null ]) : mixed
    Parameters
- $fn : callable = null
 
StartTrans()
Begin a smart transaction
    public
    abstract                StartTrans() : mixed
    Time()
An alias for the UnixTimestamp method.
    public
                    Time() : int
    Return values
intUnixDate()
Generate a unix timestamp representing the current date at midnight.
    public
                    UnixDate() : int
    Return values
intUnixTimeStamp()
A convenience method for converting a database specific string representing a date and time into a unix timestamp.
    public
                    UnixTimeStamp(string $str) : int
    Parameters
- $str : string