ratatoeskr/sys/db.php

Helper functions for dealing with MySQL.

License

This file is part of Ratatöskr.  Ratatöskr is licensed unter the MIT / X11 License.  See “ratatoeskr/licenses/ratatoeskr” for more information.

Summary
ratatoeskr/sys/db.phpHelper functions for dealing with MySQL.
Functions
db_connectEstablish a connection to the MySQL database.
sub_prefixSubstitutes “PREFIX_” in the input string with the prefix from the config.
prep_stmtPrepares a SQL statement using the global DB connection.
qdbPrepares statement (1st argument) with prep_stmt and executes it with the remaining arguments.
TransactionMakes using transactions easier.
Functions
__constructStart a new transaction.
commitCommit the transaction.
rollbackToll the transaction back.

Functions

db_connect

function db_connect()

Establish a connection to the MySQL database.

sub_prefix

function sub_prefix($q)

Substitutes “PREFIX_” in the input string with the prefix from the config.

prep_stmt

function prep_stmt($q)

Prepares a SQL statement using the global DB connection.  This will also replace “PREFIX_” with the prefix defined in ‘config.php’.

Parameters

$qThe query / statement to prepare.

Returns

A PDOStatement object.

qdb

function qdb()

Prepares statement (1st argument) with prep_stmt and executes it with the remaining arguments.

Returns

A PDOStatement object.

Transaction

Makes using transactions easier.

Summary
Functions
__constructStart a new transaction.
commitCommit the transaction.
rollbackToll the transaction back.

Functions

__construct

public function __construct()

Start a new transaction.

commit

public function commit()

Commit the transaction.

rollback

public function rollback()

Toll the transaction back.

function db_connect()
Establish a connection to the MySQL database.
function sub_prefix($q)
Substitutes “PREFIX_” in the input string with the prefix from the config.
function prep_stmt($q)
Prepares a SQL statement using the global DB connection.
function qdb()
Prepares statement (1st argument) with prep_stmt and executes it with the remaining arguments.
public function __construct()
Start a new transaction.
public function commit()
Commit the transaction.
public function rollback()
Toll the transaction back.
Close