phpBB API Documentation
Class

dbal

class dbal

Database Abstraction Layer

Properties

$db_connect_id
$query_result
$return_on_error
$transaction
$sql_time
$num_queries
$open_queries
$curtime
$query_hold
$html_hold
$sql_report
$persistency
$user
$server
$dbname
$sql_error_triggered
$sql_error_sql
$sql_error_returned
$transactions
$multi_insert
$sql_layer Current sql layer
$any_char Wildcards for matching any (%) or exactly one (_) character within LIKE expressions
$one_char
$sql_server_version Exact version of the DBAL, directly queried

Methods

dbal()

Constructor

sql_return_on_error($fail = false)

return on error or display error message

sql_num_queries($cached = false)

Return number of sql queries and cached sql queries used

sql_add_num_queries($cached = false)

Add to query count

sql_close()

DBAL garbage collection, close sql connection

sql_query_limit($query, $total, $offset, $cache_ttl)

Build LIMIT query Doing some validation here.

sql_fetchrowset($query_id = false)

Fetch all rows

sql_rowseek($rownum, $query_id)

Seek to given row number rownum is zero-based

sql_fetchfield($field, $rownum = false, $query_id = false)

Fetch field if rownum is false, the current row is used, else it is pointing to the row (zero-based)

string sql_like_expression(string $expression)

Correctly adjust LIKE expression for special characters Some DBMS are handling them in a different way

bool sql_buffer_nested_transactions()

Returns whether results of a query need to be buffered to run a transaction while iterating over them.

sql_transaction($status = 'begin')

SQL Transaction

sql_build_array($query, $assoc_ary = false)

Build sql statement from array for insert/update/select statements

sql_in_set($field, $array, $negate = false, $allow_empty_set = false)

Build IN or NOT IN sql comparison string, uses <> or = on single element arrays to improve comparison speed

sql_bit_and(string $column_name, int $bit, string $compare = '')

Run binary AND operator on DB column.

sql_bit_or(string $column_name, int $bit, string $compare = '')

Run binary OR operator on DB column.

string sql_lower_text(string $column_name)

Run LOWER() on DB column of type text (i.e.

bool sql_multi_insert(string $table, array $sql_ary)

Run more than one insert statement.

_sql_validate_value($var)

Function for validating values

sql_build_query($query, $array)

Build sql statement from array for select and select distinct statements

sql_error($sql = '')

display sql error page

sql_report($mode, $query = '')

Explain queries

string get_estimated_row_count(string $table_name)

Gets the estimated number of rows in a specified table.

string get_row_count(string $table_name)

Gets the exact number of rows in a specified table.

Details

at line 76
public dbal()

Constructor

at line 96
public sql_return_on_error($fail = false)

return on error or display error message

Parameters

$fail

at line 107
public sql_num_queries($cached = false)

Return number of sql queries and cached sql queries used

Parameters

$cached

at line 115
public sql_add_num_queries($cached = false)

Add to query count

Parameters

$cached

at line 125
public sql_close()

DBAL garbage collection, close sql connection

at line 159
public sql_query_limit($query, $total, $offset, $cache_ttl)

Build LIMIT query Doing some validation here.

Parameters

$query
$total
$offset
$cache_ttl

at line 176
public sql_fetchrowset($query_id = false)

Fetch all rows

Parameters

$query_id

at line 201
public sql_rowseek($rownum, $query_id)

Seek to given row number rownum is zero-based

Parameters

$rownum
$query_id

at line 244
public sql_fetchfield($field, $rownum = false, $query_id = false)

Fetch field if rownum is false, the current row is used, else it is pointing to the row (zero-based)

Parameters

$field
$rownum
$query_id

at line 279
public string sql_like_expression(string $expression)

Correctly adjust LIKE expression for special characters Some DBMS are handling them in a different way

Parameters

string $expression The expression to use. Every wildcard is escaped, except $this->anychar and $this->onechar

Return Value

string LIKE expression including the keyword!

at line 292
public bool sql_buffer_nested_transactions()

Returns whether results of a query need to be buffered to run a transaction while iterating over them.

Return Value

bool Whether buffering is required.

at line 301
public sql_transaction($status = 'begin')

SQL Transaction

Parameters

$status

at line 370
public sql_build_array($query, $assoc_ary = false)

Build sql statement from array for insert/update/select statements

Idea for this from Ikonboard Possible query values: INSERT, INSERT_SELECT, UPDATE, SELECT

Parameters

$query
$assoc_ary

at line 425
public sql_in_set($field, $array, $negate = false, $allow_empty_set = false)

Build IN or NOT IN sql comparison string, uses <> or = on single element arrays to improve comparison speed

Parameters

$field
$array
$negate
$allow_empty_set

at line 475
public sql_bit_and(string $column_name, int $bit, string $compare = '')

Run binary AND operator on DB column.

Results in sql statement: "{$column_name} & (1 << {$bit}) {$compare}"

Parameters

string $column_name The column name to use
int $bit The value to use for the AND operator, will be converted to (1 << $bit). Is used by options, using the number schema... 0, 1, 2...29
string $compare Any custom SQL code after the check (for example "= 0")

at line 493
public sql_bit_or(string $column_name, int $bit, string $compare = '')

Run binary OR operator on DB column.

Results in sql statement: "{$column_name} | (1 << {$bit}) {$compare}"

Parameters

string $column_name The column name to use
int $bit The value to use for the OR operator, will be converted to (1 << $bit). Is used by options, using the number schema... 0, 1, 2...29
string $compare Any custom SQL code after the check (for example "= 0")

at line 510
public string sql_lower_text(string $column_name)

Run LOWER() on DB column of type text (i.e.

neither varchar nor char).

Parameters

string $column_name The column name to use

Return Value

string A SQL statement like "LOWER($column_name)"

at line 524
public bool sql_multi_insert(string $table, array $sql_ary)

Run more than one insert statement.

Parameters

string $table table name to run the statements on
array $sql_ary multi-dimensional array holding the statement data.

Return Value

bool false if no statements were executed.

at line 577
public _sql_validate_value($var)

Function for validating values

Parameters

$var

at line 598
public sql_build_query($query, $array)

Build sql statement from array for select and select distinct statements

Possible query values: SELECT, SELECT_DISTINCT

Parameters

$query
$array

at line 701
public sql_error($sql = '')

display sql error page

Parameters

$sql

at line 771
public sql_report($mode, $query = '')

Explain queries

Parameters

$mode
$query

at line 969
public string get_estimated_row_count(string $table_name)

Gets the estimated number of rows in a specified table.

Parameters

string $table_name Table name

Return Value

string Number of rows in $table_name. Prefixed with ~ if estimated (otherwise exact).

at line 983
public string get_row_count(string $table_name)

Gets the exact number of rows in a specified table.

Parameters

string $table_name Table name

Return Value

string Exact number of rows in $table_name.