This object is the link to the database It can be used as a singleton (see function self::iGet())

uses a request sent to the database
uses a result from database
uses the exceptions handler
uses get/save results from/to cache
package OWR
used_by \OWR\CLI\Controller
used_by \OWR\DAO
used_by \OWR\REST\Controller
used_by \OWR\Controller
used_by \OWR\Model
used_by \OWR\Cron
used_by \OWR\User
used_by \OWR\Session

 Methods

Constructor It will try to connect to the database and set utf8 character set @ and set the default cache life time

__construct() 
access public
author Pierre-Alain Mignot

Starts transaction mode

beginTransaction() 
access public
author Pierre-Alain Mignot

Executes a query (cached)

cExecute(string $sql, \OWR\DB\Request $datas, boolean $prepare) : \OWR\OWR\DB\Result
access public
author Pierre-Alain Mignot

Parameters

$sql

string

the query

$datas

\OWR\OWR\DB\Request

the request

$prepare

boolean

prepare or not the query

Returns

\OWR\OWR\DB\Resultthe result

Executes a prepared query (cached)

cExecuteP(string $sql, \OWR\DB\Request $datas) : \OWR\OWR\DB\Result
access public
author Pierre-Alain Mignot

Parameters

$sql

string

the query

$datas

\OWR\OWR\DB\Request

the request

Returns

\OWR\OWR\DB\Resultthe result

Executes a query (cached) and returns all the rows

cGetAll(string $sql, string $action) : \OWR\OWR\DB\Result
access public
author Pierre-Alain Mignot

Parameters

$sql

string

the query

$action

string

the action

Returns

\OWR\OWR\DB\Resultthe result

Executes a prepared query (cached) and returns all the rows

cGetAllP(string $sql, \OWR\DB\Request $datas, string $action, boolean $prepare) : \OWR\OWR\DB\Result
access public
author Pierre-Alain Mignot

Parameters

$sql

string

the query

$datas

\OWR\OWR\DB\Request

the request

$action

string

the action

$prepare

boolean

prepare or not the query

Returns

\OWR\OWR\DB\Resultthe result

Executes a query (cached) and returns the first field from the first row

cGetOne(string $sql) : \OWR\OWR\DB\Result
access public
author Pierre-Alain Mignot

Parameters

$sql

string

the query

Returns

\OWR\OWR\DB\Resultthe result

Executes a prepared query (cached) and returns the first field from the first row

cGetOneP(string $sql, \OWR\DB\Request $datas, string $prepared) : \OWR\OWR\DB\Result
access public
author Pierre-Alain Mignot

Parameters

$sql

string

the query

$datas

\OWR\OWR\DB\Request

the request

$prepared

string

prepare or not the query

Returns

\OWR\OWR\DB\Resultthe result

Executes a query (cached) and returns the first row

cGetRow(string $sql) : \OWR\OWR\DB\Result
access public
author Pierre-Alain Mignot

Parameters

$sql

string

the query

Returns

\OWR\OWR\DB\Resultthe result

Executes a prepared query (cached) and returns the first row

cGetRowP(string $sql, \OWR\DB\Request $datas, string $prepared) : \OWR\OWR\DB\Result
access public
author Pierre-Alain Mignot

Parameters

$sql

string

the query

$datas

\OWR\OWR\DB\Request

the request

$prepared

string

prepare or not the query

Returns

\OWR\OWR\DB\Resultthe result

Commits to the database

commit(mixed $stmt) 
access public
author Pierre-Alain Mignot

Parameters

$stmt

mixed

the PDOStatement to unset, optionnal

Executes a query

execute(string $sql, \OWR\DB\Request $datas, boolean $prepare) : \OWR\OWR\DB\Result
access public
author Pierre-Alain Mignot

Parameters

$sql

string

the query

$datas

\OWR\OWR\DB\Request

the request

$prepare

boolean

prepare or not the query

Returns

\OWR\OWR\DB\Resultthe result

Executes a prepared query

executeP(string $sql, \OWR\DB\Request $datas) : mixed
access public
author Pierre-Alain Mignot

Parameters

$sql

string

the query

$datas

\OWR\OWR\DB\Request

the request

Returns

mixedan Result

Executes a query and returns the result

get(string $sql, \OWR\DB\Request $datas, string $action, boolean $returnId) : mixed
access public
author Pierre-Alain Mignot

Parameters

$sql

string

the query

$datas

\OWR\OWR\DB\Request

the request

$action

string

the action

$returnId

boolean

shall we return ID of inserted row

Returns

mixeda PDOStatement or the inserted ID

Executes a query and returns all the rows

getAll(string $sql, string $action) : \OWR\OWR\DB\Result
access public
author Pierre-Alain Mignot

Parameters

$sql

string

the query

$action

string

the action

Returns

\OWR\OWR\DB\Resultthe result

Executes a prepared query and returns all the rows

getAllP(string $sql, \OWR\DB\Request $datas, string $action, string $prepare) : \OWR\OWR\DB\Result
access public
author Pierre-Alain Mignot

Parameters

$sql

string

the query

$datas

\OWR\OWR\DB\Request

the request

$action

string

the action

$prepare

string

prepare or not the query

Returns

\OWR\OWR\DB\Resultthe result

Executes a query and returns the first field of the first row of the result

getOne(string $sql) : \OWR\OWR\DB\Result
access public
author Pierre-Alain Mignot

Parameters

$sql

string

the query

Returns

\OWR\OWR\DB\Resultthe result

Executes a prepared query and returns the first field of the first row of the result

getOneP(string $sql, \OWR\DB\Request $datas, boolean $prepared) : \OWR\OWR\DB\Result
access public
author Pierre-Alain Mignot

Parameters

$sql

string

the query

$datas

\OWR\OWR\DB\Request

the request

$prepared

boolean

prepare the query or not

Returns

\OWR\OWR\DB\Resultthe result

Executes a prepared query and returns the result

getP(string $sql, \OWR\DB\Request $datas, string $action, boolean $prepare, boolean $returnId) : mixed
access public
author Pierre-Alain Mignot

Parameters

$sql

string

the query

$datas

\OWR\OWR\DB\Request

the request

$action

string

the action

$prepare

boolean

prepare or not the query

$returnId

boolean

shall we return ID of inserted row

Returns

mixeda PDOStatement or the inserted ID

Executes a query and returns the first row of the result

getRow(string $sql) : \OWR\OWR\DB\Result
access public
author Pierre-Alain Mignot

Parameters

$sql

string

the query

Returns

\OWR\OWR\DB\Resultthe result

Executes a prepared query and returns the first row of the result

getRowP(string $sql, \OWR\DB\Request $datas, boolean $prepared) : \OWR\OWR\DB\Result
access public
author Pierre-Alain Mignot

Parameters

$sql

string

the query

$datas

\OWR\OWR\DB\Request

the request

$prepared

boolean

prepare the query or not

Returns

\OWR\OWR\DB\Resultthe result

Returns the added microtime of all SQL queries

getTime() : float
Static
access public
author Pierre-Alain Mignot

Returns

float$_queryTime

Singleton pattern getter

iGet() : mixed
Static
access public
static
author Pierre-Alain Mignot

Returns

mixedinstance of this object

Rollback function for transaction mode

rollback() 
access public
author Pierre-Alain Mignot

Function to quote values (sanitize)

sanitize(mixed $datas) 
access public
author Pierre-Alain Mignot

Parameters

$datas

mixed

string or array to sanitize

Executes a query and returns the result

set(string $sql, \OWR\DB\Request $datas, string $action, boolean $returnId) : mixed
access public
author Pierre-Alain Mignot

Parameters

$sql

string

the query

$datas

\OWR\OWR\DB\Request

the request

$action

string

the action

$returnId

boolean

returns the id of the inserted row

Returns

mixedthe result/statement/id

Sets the cache lifetime

setCacheTime(int $cacheTime) 
access public
author Pierre-Alain Mignot

Parameters

$cacheTime

int

the cache time, in seconds

Changes database

setDB(string $db) 
access public
author Pierre-Alain Mignot

Parameters

$db

string

the database name to connect

Executes a prepared query and returns the result

setP(string $sql, \OWR\DB\Request $datas, string $action, string $prepare, boolean $returnId) : mixed
access public
author Pierre-Alain Mignot

Parameters

$sql

string

the query

$datas

\OWR\OWR\DB\Request

the request

$action

string

the action

$prepare

string

prepare the query or not

$returnId

boolean

returns the id of the inserted row

Returns

mixedthe result/statement/id

Main execute function All public functions call this function

_executeSQL(string $sql, \OWR\DB\Request $datas, string $action, boolean $prepare, boolean $returnId) : mixed
access protected
author Pierre-Alain Mignot

Parameters

$sql

string

the query

$datas

\OWR\OWR\DB\Request

the request

$action

string

the action, if not prepared (can be 'query' or 'exec')

$prepare

boolean

prepare or not the query

$returnId

boolean

if a row is inserted, returns the id

Returns

mixedthe result/statement/id

 Properties

 

cache time

$_cacheTime : int
access protected
 

have we made modifications in the database ?

$_hasSet : boolean
access protected
 

an instance of this class to be used as a singleton

$_instance : mixed
access protected
static
 

total time of all executed queries

$_queryTime : float
access protected
static
 

stored prepared statements

$_stmts : array
access protected
 

are we in transaction mode ?

$_transaction : int
access protected