Reference ManualsDBAPI — This is the base DBAPI class.
DBAPI is part of the DBAPI package.
class DBAPI {
private array $args
private array $args_used
public bool $cast_object_to_string
public bool $compound_inserts
protected resource $last_result
private array $placeholders
public bool $return_on_error
public DBAPI __construct ( string $dsn,
string $username,
string $password,
array $options );
private string add_placeholder ( array $match );
public int affectedrows ( void );
private string build_insert_array ( array $args,
bool $use_keys );
private string build_update_array ( array $args );
public void close ( void );
private int count_vars ( string $query );
public int errno ( void );
public string error ( void );
public mixed escape ( mixed $var );
protected resource execute_query ( string $query );
public array fetchcol ( resource $result );
public array fetchrow ( resource $result );
public array fetchrowset ( resource $result );
public void freeresult ( resource $result );
private mixed get_arg ( array $key );
public mixed lastid ( void );
protected string limit_query ( string $query,
int $length,
int $start );
public array parse_dsn ( strinf $dsn );
private string parse_insert_query ( string $query,
array $args );
private array parse_query ( array $args );
private string parse_single_query ( string $query,
array $args );
public resource query ( string $query,
mixed $arg,... );
public resource query_limit ( string $query,
mixed $arg,...,
int $start,
int $length );
public mixed quote ( mixed $var );
private string restore_placeholder ( array $match );
public void return_on_error ( bool $bool );
}
DBAPI +----phppdo +----sqlite2 +----mysql
This is the base DBAPI class.
Specific implementations should subclass this base class and implement the database specific functions marked as abstract.
private array $args
An array used for the arguments to be parsed into a query
Default value: empty string
private array $args_used
An array to keep track of used arguments. This allows named arguments to be used multiple times.
Default value: empty string
public bool $cast_object_to_string
Whether to cast variables of type 'object' to string
Default value: empty string
public bool $compound_inserts
Whether or not compound insert statements shouldbe used
Default value: empty string
protected resource $last_result
The last used SQL result resource
private array $placeholders
An array containing quoted strings and their placeholders. Used during query parsing
Default value: empty string
public bool $return_on_error
Whether to return silently on an SQL error or let PHP handle it
Default value: empty string
public DBAPI __construct ( string $dsn,
string $username,
string $password,
array $options );
Create a database connection
This function is identical to PHP's PDO() constructor.
private string add_placeholder ( array $match );
A preg_replace() callback to replace a quoted string with a placeholder
public int affectedrows ( void );
Get the number of rows affected by the last query
private string build_insert_array ( array $args,
bool $use_keys );
Build an SQL insert statement out of a series of arguments
private string build_update_array ( array $args );
Build an SQL update statement out of a series of arguments
public void close ( void );
Close the database connection
private int count_vars ( string $query );
Count the number of variables/placeholders in an SQL query
public int errno ( void );
Return the last SQL error number
public string error ( void );
Return the last SQL error message
public mixed escape ( mixed $var );
Escape a variable to safely use in in SQL
protected resource execute_query ( string $query );
Execute a single SQL query
public array fetchcol ( resource $result );
Fetch an array containing the values of the first column in the result set
public array fetchrow ( resource $result );
Fetch a single row from the SQL result set. If no result is specified, it should use the protected last_result variable
public array fetchrowset ( resource $result );
Fetch an array of rows from the SQL result set. If no result is specified, it should use the protected last_result variable
public void freeresult ( resource $result );
Free an SQL result resource. If no result is specified, it should use the protected last_result variable
private mixed get_arg ( array $key );
A preg_replace callback to return a quoted/escaped argument and remove it from the SQL argument list
public mixed lastid ( void );
Get the unique ID of the last row that was insterted in the database
protected string limit_query ( string $query,
int $length,
int $start );
Modify a query to limit the size of the returned result set
public array parse_dsn ( strinf $dsn );
Parse a data source name.
This function takes a PHP PDO compatible DSN and parses it into an array containing key-value pairs from the DSN string. The database type prefix is set in the phptype field.
private string parse_insert_query ( string $query,
array $args );
Parse a two dimensional array into one big compound INSERT statement
private array parse_query ( array $args );
Parse a set of variables in one or more queries. Queries are passed in the form of array($query, [, arg [, ...]]). It determins the kind of query (INSERT or something else) and the number of queries. The actual parsing is done in parse_single_query() or parse_insert_query().
private string parse_single_query ( string $query,
array $args );
Parse a series of variables into an SQL query. Variables in the query can be specified as positional arguments ? or ar named variables {variable}. First all the named variables from the argument list are replaces, then the positional arguments from whatever is left from the argument list.
public resource query ( string $query,
mixed $arg,... );
Execute a regular SQL query
public resource query_limit ( string $query,
mixed $arg,...,
int $start,
int $length );
Execute a query and return a limited set of results
public mixed quote ( mixed $var );
Escape and properly quote a variable
private string restore_placeholder ( array $match );
A preg_replace() callback to restore a placeholder with the original text
public void return_on_error ( bool $bool );
Whether to return when an SQL error occurs (TRUE) or to trigger an error (FALSE).