rcube_db

Database independent query interface.

This is a wrapper for the PHP PDO.

package

Framework

subpackage

Database

Methods

Factory, returns driver-specific instance of the class

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

Arguments

$db_dsnw

string

DSN for read/write operations

$db_dsnr

string

Optional DSN for read only operations

$pconn

bool

Enables persistent connections

Response

\rcube_db

Object instance

Object constructor

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

Arguments

$db_dsnw

string

DSN for read/write operations

$db_dsnr

string

Optional DSN for read only operations

$pconn

bool

Enables persistent connections

Connect to specific database

dsn_connect(array $dsn, string $mode) 

Arguments

$dsn

array

DSN for DB connections

$mode

string

Connection mode (r|w)

Driver-specific preparation of database connection

conn_prepare(array $dsn) 

Arguments

$dsn

array

DSN for DB connections

Driver-specific configuration of database connection

conn_configure(array $dsn, \PDO $dbh) 

Arguments

$dsn

array

DSN for DB connections

$dbh

\PDO

Connection handler

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

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

dsn_select($query) 

Arguments

$query

Activate/deactivate debug mode

set_debug(boolean $dbg = true) 

Arguments

$dbg

boolean

True if SQL queries should be logged

Writes debug information/query to 'sql' log file

debug(string $query) 

Arguments

$query

string

SQL query

Getter for error state

is_error(mixed $result = null) : string

Arguments

$result

mixed

Optional query result

Response

string

Error message

Connection state checker

is_connected() : boolean

Response

boolean

True if in connected state

Is database replication configured?

is_replicated() : bool

Response

bool

Returns true if dsnw != dsnr

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

Execute a SQL query

query() : \number

Response

\number

Query handle identifier

Execute a SQL query with limits

limitquery() : \PDOStatement|bool

Response

\PDOStatement|bool

Query handle or False on error

Execute a SQL query with limits

_query(string $query, int $offset, int $numrows, array $params) : \PDOStatement|bool

Arguments

$query

string

SQL query to execute

$offset

int

Offset for LIMIT statement

$numrows

int

Number of rows for LIMIT statement

$params

array

Values to be inserted in query

Response

\PDOStatement|bool

Query handle or False on error

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

Get number of affected rows for the last query

affected_rows(mixed $result = null) : int

Arguments

$result

mixed

Optional query handle

Response

int

Number of (matching) rows

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

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

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

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 col values for a result row

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

Arguments

$result

mixed

Optional query handle

$mode

int

Fetch mode identifier

Response

mixed

Array with col values or false on failure

Adds LIMIT,OFFSET clauses to the query

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

Arguments

$query

string

SQL query

$limit

int

Number of rows

$offset

int

Offset

Response

string

SQL query

Returns list of tables in a database

list_tables() : array

Response

array

List of all tables of the current database

Returns list of columns in database table

list_cols(string $table) : array

Arguments

$table

string

Table name

Response

array

List of table cols

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

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

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

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

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

Return SQL function for current time and date

now(int $interval) : string

Arguments

$interval

int

Optional interval (in seconds) to add/subtract

Response

string

SQL function to use in query

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

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

Return SQL statement to convert from a unix timestamp

fromunixtime(int $timestamp) : string

Arguments

$timestamp

int

Unix timestamp

Response

string

Date string in db-specific format

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

Abstract SQL statement for value concatenation

concat() : string

Response

string

SQL statement to be used in query

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

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

Arguments

$input

mixed

Data to fix

$serialized

bool

Enable serialization

Response

mixed

Properly UTF-8 encoded data

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

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

Arguments

$input

mixed

Input data

$serialized

bool

Enable serialization

Response

mixed

Decoded data

Return correct name for a specific database table

table_name(string $table) : string

Arguments

$table

string

Table name

Response

string

Translated table name

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

MDB2 DSN string parser

parse_dsn($dsn) : array
static

Arguments

$dsn

Response

array

DSN parameters

Returns PDO DSN string from DSN array

dsn_string(array $dsn) : string

Arguments

$dsn

array

DSN parameters

Response

string

DSN string

Returns driver-specific connection options

dsn_options(array $dsn) : array

Arguments

$dsn

array

DSN parameters

Response

array

Connection options

Constants

DEBUG_LINE_LENGTH

DEBUG_LINE_LENGTH

Properties

db_provider

db_provider : 

db_dsnw

db_dsnw : 

db_dsnr

db_dsnr : 

db_connected

db_connected : 

db_mode

db_mode : 

db_table_dsn_map

db_table_dsn_map : 

dbh

dbh : 

dbhs

dbhs : 

table_connections

table_connections : 

db_error

db_error : 

db_error_msg

db_error_msg : 

conn_failure

conn_failure : 

db_index

db_index : 

last_result

last_result : 

tables

tables : 

variables

variables : 

options

options :