class PDOConnector extends DBConnector

PDO driver database connector

Config options

emulate_prepare boolean Should ATTR_EMULATE_PREPARES flag be used to emulate prepared statements?
ssl_cipher_default string Default strong SSL cipher to be used

Methods

bool
isQueryMutable(string $sql)

Determine if this SQL statement is a destructive operation (write or ddl)

bool
isQueryDDL(string $sql)

Determine if this SQL statement is a DDL operation

bool
isQueryWrite(string $sql)

Determine if this SQL statement is a write operation (alters content but not structure)

connect(array $parameters, boolean $selectDB = false)

Link this connector to the database given the specified parameters Will throw an exception rather than return a success state.

string
getVersion()

Query for the version of the currently connected database

string
escapeString(string $value)

Given a value escape this for use in a query for the current database connector. Note that this does not quote the value.

string
quoteString(string $value)

Given a value escape and quote this appropriately for the current database connector.

escapeIdentifier(string $value, string $separator = '.')

Escapes an identifier (table / database name). Typically the value is simply double quoted. Don't pass in already escaped identifiers in, as this will double escape the value!

query(string $sql, integer $errorLevel = E_USER_ERROR)

Executes the following query with the specified error level.

preparedQuery(string $sql, array $parameters, int $errorLevel = E_USER_ERROR)

Execute the given SQL parameterised query with the specified arguments

boolean
selectDatabase(string $name)

Select a database by name

string
getSelectedDatabase()

Retrieves the name of the currently selected database

unloadDatabase()

De-selects the currently selected database

string
getLastError()

Retrieves the last error generated from the database connection

integer
getGeneratedID(string $table)

Determines the last ID generated from the specified table.

integer
affectedRows()

Determines the number of affected rows from the last SQL query

boolean
isActive()

Determines if we are connected to a server AND have a valid database selected.

flushStatements()

Flush all prepared statements

getOrPrepareStatement(string $sql)

Retrieve a prepared statement for a given SQL string, or return an already prepared version if one exists for the given query

static boolean
is_emulate_prepare()

Is PDO running in emulated mode

int
exec(string $sql, integer $errorLevel = E_USER_ERROR)

Executes a query that doesn't return a resultset

integer
getPDOParamType(string $phpType)

Determines the PDO::PARAM_* type for a given PHP type string

bindParameters(PDOStatement $statement, array $parameters)

Bind all parameters to a PDOStatement

Details

in DBConnector at line 67
bool isQueryMutable(string $sql)

Determine if this SQL statement is a destructive operation (write or ddl)

Parameters

string $sql

Return Value

bool

in DBConnector at line 81
bool isQueryDDL(string $sql)

Determine if this SQL statement is a DDL operation

Parameters

string $sql

Return Value

bool

in DBConnector at line 93
bool isQueryWrite(string $sql)

Determine if this SQL statement is a write operation (alters content but not structure)

Parameters

string $sql

Return Value

bool

at line 103
connect(array $parameters, boolean $selectDB = false)

Link this connector to the database given the specified parameters Will throw an exception rather than return a success state.

The connector should not select the database once connected until explicitly called by selectDatabase()

Parameters

array $parameters List of parameters such as

  • type
  • server
  • username
  • password
  • database
  • path
boolean $selectDB By default database selection should be handled by the database controller (to enable database creation on the fly if necessary), but some interfaces require that the database is specified during connection (SQLite, Azure, etc).

at line 208
string getVersion()

Query for the version of the currently connected database

Return Value

string Version of this database

at line 212
string escapeString(string $value)

Given a value escape this for use in a query for the current database connector. Note that this does not quote the value.

Parameters

string $value The value to be escaped

Return Value

string The appropritaely escaped string for value

at line 223
string quoteString(string $value)

Given a value escape and quote this appropriately for the current database connector.

Parameters

string $value The value to be injected into a query

Return Value

string The appropriately escaped and quoted string for $value

in DBConnector at line 185
escapeIdentifier(string $value, string $separator = '.')

Escapes an identifier (table / database name). Typically the value is simply double quoted. Don't pass in already escaped identifiers in, as this will double escape the value!

Parameters

string $value The identifier to escape
string $separator optional identifier splitter

at line 266
query(string $sql, integer $errorLevel = E_USER_ERROR)

Executes the following query with the specified error level.

Implementations of this function should respect previewWrite and benchmarkQuery

Parameters

string $sql The SQL query to execute
integer $errorLevel For errors to this query, raise PHP errors using this error level.

at line 331
SS_Query preparedQuery(string $sql, array $parameters, int $errorLevel = E_USER_ERROR)

Execute the given SQL parameterised query with the specified arguments

Parameters

string $sql The SQL query to execute. The ? character will denote parameters.
array $parameters An ordered list of arguments.
int $errorLevel The level of error reporting to enable for the query

Return Value

SS_Query

at line 425
boolean selectDatabase(string $name)

Select a database by name

Parameters

string $name Name of database

Return Value

boolean Flag indicating success

at line 431
string getSelectedDatabase()

Retrieves the name of the currently selected database

Return Value

string Name of the database, or null if none selected

at line 435
unloadDatabase()

De-selects the currently selected database

at line 405
string getLastError()

Retrieves the last error generated from the database connection

Return Value

string The error message

at line 417
integer getGeneratedID(string $table)

Determines the last ID generated from the specified table.

Note that some connectors may not be able to return $table specific responses, and this parameter may be ignored.

Parameters

string $table The target table to return the last generated ID for

Return Value

integer ID value

at line 421
integer affectedRows()

Determines the number of affected rows from the last SQL query

Return Value

integer Number of affected rows

at line 439
boolean isActive()

Determines if we are connected to a server AND have a valid database selected.

Return Value

boolean Flag indicating that a valid database is connected

at line 64
flushStatements()

Flush all prepared statements

at line 75
PDOStatement getOrPrepareStatement(string $sql)

Retrieve a prepared statement for a given SQL string, or return an already prepared version if one exists for the given query

Parameters

string $sql

Return Value

PDOStatement

at line 99
static boolean is_emulate_prepare()

Is PDO running in emulated mode

Return Value

boolean

at line 251
int exec(string $sql, integer $errorLevel = E_USER_ERROR)

Executes a query that doesn't return a resultset

Parameters

string $sql The SQL query to execute
integer $errorLevel For errors to this query, raise PHP errors using this error level.

Return Value

int

at line 281
integer getPDOParamType(string $phpType)

Determines the PDO::PARAM_* type for a given PHP type string

Parameters

string $phpType Type of object in PHP

Return Value

integer PDO Parameter constant value

at line 310
bindParameters(PDOStatement $statement, array $parameters)

Bind all parameters to a PDOStatement

Parameters

PDOStatement $statement
array $parameters