rcube_db

Database independent query interface.

This is a wrapper for the PHP PDO.

package

Framework

subpackage

Database

Methods

Object constructor

__construct(string $db_dsnw, string $db_dsnr = '', boolean $pconn = false) 

Arguments

$db_dsnw

string

DSN for read/write operations

$db_dsnr

string

Optional DSN for read only operations

$pconn

boolean

Enables persistent connections

Get col values for a result row

_fetch_row(mixed $result, integer $mode) : mixed

Arguments

$result

mixed

Optional query handle

$mode

integer

Fetch mode identifier

Response

mixed

Array with col values or false on failure

Execute a SQL query with limits

_query(string $query, integer $offset, integer $numrows, array $params) : \PDOStatement|boolean

Arguments

$query

string

SQL query to execute

$offset

integer

Offset for LIMIT statement

$numrows

integer

Number of rows for LIMIT statement

$params

array

Values to be inserted in query

Response

\PDOStatement|boolean

Query handle or False on error

Get number of affected rows for the last query

affected_rows(mixed $result = null) : integer

Arguments

$result

mixed

Optional query handle

Response

integer

Number of (matching) rows

Return list of elements for use with SQL's IN clause

array2list(array $arr, string $type = null) : string

Arguments

$arr

array

Input array

$type

string

Type of data (integer, bool, ident)

Response

string

Comma-separated list of quoted values for use in query

Terminate database connection.

closeConnection() 

Abstract SQL statement for value concatenation

concat() : string

Response

string

SQL statement to be used in query

Driver-specific configuration of database connection

conn_configure(array $dsn, \PDO $dbh) 

Arguments

$dsn

array

DSN for DB connections

$dbh

\PDO

Connection handler

Create PDO connection

conn_create( $dsn) 

Arguments

$dsn

Driver-specific preparation of database connection

conn_prepare(array $dsn) 

Arguments

$dsn

array

DSN for DB connections

Connect to appropriate database depending on the operation

db_connect(string $mode, boolean $force = false) 

Arguments

$mode

string

Connection mode (r|w)

$force

boolean

Enforce using the given mode

Writes debug information/query to 'sql' log file

debug(string $query) 

Arguments

$query

string

SQL query

Decodes encoded UTF-8 string/object/array (recursive)

decode(mixed $input, boolean $serialized = false) : mixed
static

Arguments

$input

mixed

Input data

$serialized

boolean

Enable serialization

Response

mixed

Decoded data

Connect to specific database

dsn_connect(array $dsn, string $mode) 

Arguments

$dsn

array

DSN for DB connections

$mode

string

Connection mode (r|w)

Returns driver-specific connection options

dsn_options(array $dsn) : array

Arguments

$dsn

array

DSN parameters

Response

array

Connection options

Analyze the given SQL statement and select the appropriate connection to use

dsn_select( $query) 

Arguments

$query

Returns PDO DSN string from DSN array

dsn_string(array $dsn) : string

Arguments

$dsn

array

DSN parameters

Response

string

DSN string

Encodes non-UTF-8 characters in string/array/object (recursive)

encode(mixed $input, boolean $serialized = false) : mixed
static

Arguments

$input

mixed

Data to fix

$serialized

boolean

Enable serialization

Response

mixed

Properly UTF-8 encoded data

Commit transaction

endTransaction() : boolean

Response

boolean

True on success, False on failure

Escapes a string so it can be safely used in a query

escape(string $str) : string

Arguments

$str

string

A string to escape

Response

string

Escaped string for use in a query

Escapes a string so it can be safely used in a query

escapeSimple(string $str) : string
deprecated

Replaced by rcube_db::escape

see \rcube_db::escape

Arguments

$str

string

A string to escape

Response

string

Escaped string for use in a query

Execute the given SQL script

exec_script( $sql) : \boolen

Arguments

$sql

Response

\boolen

True on success, False on error

Factory, returns driver-specific instance of the class

factory(string $db_dsnw, string $db_dsnr = '', boolean $pconn = false) : \rcube_db
static

Arguments

$db_dsnw

string

DSN for read/write operations

$db_dsnr

string

Optional DSN for read only operations

$pconn

boolean

Enables persistent connections

Response

\rcube_db

Object instance

Get an index array for one row If no query handle is specified, the last query will be taken as reference

fetch_array(mixed $result = null) : mixed

Arguments

$result

mixed

Optional query handle

Response

mixed

Array with col values or false on failure

Get an associative array for one row If no query handle is specified, the last query will be taken as reference

fetch_assoc(mixed $result = null) : mixed

Arguments

$result

mixed

Optional query handle

Response

mixed

Array with col values or false on failure

Parse SQL file and fix table names according to table prefix

fix_table_names( $sql) 

Arguments

$sql

Preg_replace callback for fix_table_names()

fix_table_names_callback( $matches) 

Arguments

$matches

Return SQL statement to convert from a unix timestamp

fromunixtime(integer $timestamp) : string

Arguments

$timestamp

integer

Unix timestamp

Response

string

Date string in db-specific format

Get database runtime variables

get_variable(string $varname, mixed $default = null) : mixed

Arguments

$varname

string

Variable name

$default

mixed

Default value if variable is not set

Response

mixed

Variable value or default

Helper method to handle DB errors.

handle_error( $query) : mixed

This by default logs the error but could be overriden by a driver implementation

Arguments

$query

Response

mixed

Result to be stored and returned

Return SQL statement for case insensitive LIKE

ilike(string $column, string $value) : string

Arguments

$column

string

Field name

$value

string

Search value

Response

string

SQL statement to use in query

Get last inserted record ID

insert_id(string $table = '') : mixed

Arguments

$table

string

Table name (to find the incremented sequence)

Response

mixed

ID or false on failure

Connection state checker

is_connected() : boolean

Response

boolean

True if in connected state

Getter for error state

is_error(mixed $result = null) : string

Arguments

$result

mixed

Optional query result

Response

string

Error message

Is database replication configured?

is_replicated() : boolean

Response

boolean

Returns true if dsnw != dsnr

Execute a SQL query with limits

limitquery() : \PDOStatement|boolean

Response

\PDOStatement|boolean

Query handle or False on error

Returns list of columns in database table

list_cols(string $table) : array

Arguments

$table

string

Table name

Response

array

List of table cols

Returns list of tables in a database

list_tables() : array

Response

array

List of all tables of the current database

Return SQL function for current time and date

now(integer $interval) : string

Arguments

$interval

integer

Optional interval (in seconds) to add/subtract

Response

string

SQL function to use in query

Get number of rows for a SQL query If no query handle is specified, the last query will be taken as reference

num_rows(mixed $result = null) : mixed
deprecated

This method shows very poor performance and should be avoided.

Arguments

$result

mixed

Optional query handle

Response

mixed

Number of rows or false on failure

MDB2 DSN string parser

parse_dsn( $dsn) : array
static

Arguments

$dsn

Response

array

DSN parameters

Execute a SQL query

query() : \number

Response

\number

Query handle identifier

Query execution

query_execute( $query) 

Arguments

$query

Parse SQL query and replace identifier quoting

query_parse(string $query) : string

Arguments

$query

string

SQL query

Response

string

SQL query

Formats input so it can be safely used in a query

quote(mixed $input, string $type = null) : string

Arguments

$input

mixed

Value to quote

$type

string

Type of data (integer, bool, ident)

Response

string

Quoted/converted string for use in query

Quotes a string so it can be safely used as a table or column name

quote_identifier(string $str) : string

Arguments

$str

string

Value to quote

Response

string

Quoted string for use in query

Quotes a string so it can be safely used as a table or column name

quoteIdentifier(string $str) : string
deprecated

Replaced by rcube_db::quote_identifier

see \rcube_db::quote_identifier

Arguments

$str

string

Value to quote

Response

string

Quoted string for use in query

Rollback transaction

rollbackTransaction() : boolean

Response

boolean

True on success, False on failure

Activate/deactivate debug mode

set_debug(boolean $dbg = true) 

Arguments

$dbg

boolean

True if SQL queries should be logged

Adds LIMIT,OFFSET clauses to the query

set_limit(string $query, integer $limit, integer $offset) : string

Arguments

$query

string

SQL query

$limit

integer

Number of rows

$offset

integer

Offset

Response

string

SQL query

Set class option value

set_option(string $name, mixed $value) 

Arguments

$name

string

Option name

$value

mixed

Option value

Set DSN connection to be used for the given table

set_table_dsn( $table,  $mode) 

Arguments

$table

$mode

Start transaction

startTransaction() : boolean

Response

boolean

True on success, False on failure

Return correct name for a specific database table

table_name(string $table, boolean $quoted = false) : string

Arguments

$table

string

Table name

$quoted

boolean

Quote table identifier

Response

string

Translated table name

Return SQL statement to convert a field value into a unix timestamp

unixtimestamp(string $field) : string

This method is deprecated and should not be used anymore due to limitations of timestamp functions in Mysql (year 2038 problem)

deprecated

Arguments

$field

string

Field name

Response

string

SQL statement to use in query

Constants

DEBUG_LINE_LENGTH

DEBUG_LINE_LENGTH

DEFAULT_QUOTE

DEFAULT_QUOTE

Properties

db_provider

db_provider : 

Type(s)

db_dsnw

db_dsnw : 

Type(s)

db_dsnr

db_dsnr : 

Type(s)

db_connected

db_connected : 

Type(s)

db_mode

db_mode : 

Type(s)

dbh

dbh : 

Type(s)

dbhs

dbhs : 

Type(s)

table_connections

table_connections : 

Type(s)

db_error

db_error : 

Type(s)

db_error_msg

db_error_msg : 

Type(s)

conn_failure

conn_failure : 

Type(s)

db_index

db_index : 

Type(s)

last_result

last_result : 

Type(s)

tables

tables : 

Type(s)

variables

variables : 

Type(s)

options

options : 

Type(s)