Constants

INSERT

INSERT

Constants used by insert() method

INSERT_IGNORE

INSERT_IGNORE

REPLACE

REPLACE

Properties

$server

$server : string

Type

string — Server (eg. localhost)

$user

$user : string

Type

string — Database user (eg. root)

$password

$password : string

Type

string — Database password (eg. can be empty !)

$database

$database : string

Type

string — Database name

$is_cache_enabled

$is_cache_enabled : boolean

Type

boolean

$link

$link : mixed

Type

mixed — Ressource link

$result

$result : mixed

Type

mixed — SQL cached result

$instance

$instance : array

Type

array — List of DB instance

$_servers

$_servers : array

Type

array — Object instance for singleton

$last_query

$last_query : string

Store last executed query

Type

string

$last_cached

$last_cached : string

Last cached query

Type

string

Methods

connect()

connect() 

Open a connection

disconnect()

disconnect() 

Close a connection

Insert_ID()

Insert_ID() 

Get the ID generated from the previous INSERT operation

Affected_Rows()

Affected_Rows() 

Get number of affected rows in previous database operation

nextRow()

nextRow(mixed  $result = false) 

Get next row for a query which doesn't return an array

Parameters

mixed $result

getVersion()

getVersion() : string

Get database version

Returns

string

_escape()

_escape(string  $str) : string

Protect string against SQL injections

Parameters

string $str

Returns

string

getMsgError()

getMsgError() 

Returns the text of the error message from previous database operation

getNumberError()

getNumberError() 

Returns the number of the error from previous database operation

set_db()

set_db(  $db_name) 

Parameters

$db_name

getBestEngine()

getBestEngine() 

getInstance()

getInstance(boolean  $master = true) : \Db

Get Db object instance

Parameters

boolean $master

Decides whether the connection to be returned by the master server or the slave server

Returns

\Db —

instance

getClass()

getClass() : string

Get child layer class

Returns

string

__construct()

__construct(string  $server, string  $user, string  $password, string  $database, boolean  $connect = true) 

Instantiate database connection

Parameters

string $server

Server address

string $user

User login

string $password

User password

string $database

Database name

boolean $connect

If false, don't connect in constructor (since 1.5.0)

__destruct()

__destruct() 

Close connection to database

autoExecute()

autoExecute(  $table,   $data,   $type,   $where = '',   $limit,   $use_cache = true,   $use_null = false) 

Parameters

$table
$data
$type
$where
$limit
$use_cache
$use_null

autoExecuteWithNullValues()

autoExecuteWithNullValues(string  $table, string  $values, string  $type, string  $where = '', integer  $limit) : mixed|boolean

Filter SQL query within a blacklist

Parameters

string $table

Table where insert/update data

string $values

Data to insert/update

string $type

INSERT or UPDATE

string $where

WHERE clause, only for UPDATE (optional)

integer $limit

LIMIT clause (optional)

Returns

mixed|boolean —

SQL query result

query()

query(string  $sql) : mixed

Execute a query and get result ressource

Parameters

string $sql

Returns

mixed

insert()

insert(string  $table, array  $data, boolean  $null_values = false, boolean  $use_cache = true, integer  $type = \Db::INSERT, boolean  $add_prefix = true) : boolean

Execute an INSERT query

Parameters

string $table

Table name without prefix

array $data

Data to insert as associative array. If $data is a list of arrays, multiple insert will be done

boolean $null_values

If we want to use NULL values instead of empty quotes

boolean $use_cache
integer $type

Must be Db::INSERT or Db::INSERT_IGNORE or Db::REPLACE

boolean $add_prefix

Add or not _DBPREFIX before table name

Returns

boolean

update()

update(string  $table, array  $data, string  $where = '', integer  $limit, boolean  $null_values = false, boolean  $use_cache = true, boolean  $add_prefix = true) : boolean

Parameters

string $table

Table name without prefix

array $data

Data to insert as associative array. If $data is a list of arrays, multiple insert will be done

string $where

WHERE condition

integer $limit
boolean $null_values

If we want to use NULL values instead of empty quotes

boolean $use_cache
boolean $add_prefix

Add or not _DBPREFIX before table name

Returns

boolean

delete()

delete(string  $table, string  $where = '', integer  $limit, boolean  $use_cache = true, boolean  $add_prefix = true) : boolean

Execute a DELETE query

Parameters

string $table

Name of the table to delete

string $where

WHERE clause on query

integer $limit

Number max of rows to delete

boolean $use_cache

Use cache or not

boolean $add_prefix

Add or not _DBPREFIX before table name

Returns

boolean

execute()

execute(string  $sql, boolean  $use_cache = true) : boolean

Execute a query

Parameters

string $sql
boolean $use_cache

Returns

boolean

executeS()

executeS(string  $sql, boolean  $array = true, boolean  $use_cache = true) : array

ExecuteS return the result of $sql as array

Parameters

string $sql

query to execute

boolean $array

return an array instead of a mysql_result object (deprecated since 1.5.0, use query method instead)

boolean $use_cache

if query has been already executed, use its result

Returns

array —

or result object

getRow()

getRow(mixed  $sql, boolean  $use_cache = true) : array

getRow return an associative array containing the first row of the query This function automatically add "limit 1" to the query

Parameters

mixed $sql

the select query (without "LIMIT 1")

boolean $use_cache

find it in cache first

Returns

array —

associative array of (field=>value)

getValue()

getValue(mixed  $sql, boolean  $use_cache = true) : mixed

getValue return the first item of a select query.

Parameters

mixed $sql
boolean $use_cache

Returns

mixed

numRows()

numRows() : integer

Get number of rows for last result

Returns

integer

displayError()

displayError(boolean  $sql = false) 

Display last SQL error

Parameters

boolean $sql

escape()

escape(string  $string, boolean  $html_ok = false) : string

Sanitize data which will be injected into SQL query

Parameters

string $string

SQL data which will be injected into SQL query

boolean $html_ok

Does data contain HTML code ? (optional)

Returns

string —

Sanitized data

checkConnection()

checkConnection(string  $server, string  $user, string  $pwd, string  $db, boolean  $new_db_link = true, boolean  $engine = null,   $timeout = 5) : integer

Try a connection to te database

Parameters

string $server

Server address

string $user

Login for database connection

string $pwd

Password for database connection

string $db

Database name

boolean $new_db_link
boolean $engine
$timeout

Returns

integer

checkEncoding()

checkEncoding(string  $server, string  $user, string  $pwd) : integer

Try a connection to te database

Parameters

string $server

Server address

string $user

Login for database connection

string $pwd

Password for database connection

Returns

integer

hasTableWithSamePrefix()

hasTableWithSamePrefix(string  $server, string  $user, string  $pwd, string  $db, string  $prefix) : boolean

Try a connection to the database and check if at least one table with same prefix exists

Parameters

string $server

Server address

string $user

Login for database connection

string $pwd

Password for database connection

string $db

Database name

string $prefix

Tables prefix

Returns

boolean

checkCreatePrivilege()

checkCreatePrivilege(  $server,   $user,   $pwd,   $db,   $prefix,   $engine = null) 

Parameters

$server
$user
$pwd
$db
$prefix
$engine

checkAutoIncrement()

checkAutoIncrement(  $server,   $user,   $pwd) 

Parameters

$server
$user
$pwd

s()

s(  $sql,   $use_cache = true) 

Parameters

$sql
$use_cache

ps()

ps(  $sql,   $use_cache = 1) 

Parameters

$sql
$use_cache

ds()

ds(  $sql,   $use_cache = 1) 

Parameters

$sql
$use_cache

_query()

_query(string  $sql) : mixed

Execute a query and get result resource

Parameters

string $sql

Returns

mixed

_numRows()

_numRows(mixed  $result) 

Get number of rows in a result

Parameters

mixed $result

getAll()

getAll(mixed  $result = false) 

Get all rows for a query which return an array

Parameters

mixed $result

loadSlaveServers()

loadSlaveServers() 

q()

q(string  $sql, boolean  $use_cache = true) : mixed

Execute a query

Parameters

string $sql
boolean $use_cache

Returns

mixed —

$result