Topics

Class Db

Database connector

Namespace: Ip

Methods:

__construct( [ mixed $pdo = null ] )
PDO getConnection( )

Get database connection object

Return values:

PDO

Throws:

Ip\Exception\Db
setConnection( mixed $connection )
disconnect( )

Disconnect from the database

string|null fetchValue( string $sql , [ array $params = array() ] )

Execute SQL query and fetch a value from the result set.

Parameters:

string $sql
array $params

Return values:

string|null

Throws:

Ip\Exception\Db
array|null fetchRow( mixed $sql , [ array $params = array() ] )

Execute SQL query and fetch a single row from the result set

Parameters:

mixed $sql
array $params

Return values:

array|null

Throws:

Ip\Exception\Db
array fetchAll( mixed $sql , [ array $params = array() ] )

Execute SQL query and fetch all query results

Parameters:

mixed $sql
array $params

Return values:

array

Throws:

Ip\Exception\Db
array selectAll( string $table , array|string $columns , [ array $where = array() ] , [ string $sqlEnd = '' ] )

Execute SELECT query on specified table and return array with results

Parameters:

string $table Table name without prefix
array|string $columns list of columns or string. For example array('id', 'name') or '*'.
array $where Conditional array. For example array('id' => 20)
string $sqlEnd SQL string appended at the end of the query. For example 'ORDER BY createdAt DESC'

Return values:

array
array|null selectRow( string $table , array|string $columns , array $where , [ string $sqlEnd = '' ] )

Execute SELECT query and return a single row

Parameters:

string $table Table name without prefix
array|string $columns List of columns as array or string. For example array('id', 'name') or '*'.
array $where Conditional array. For example array('id' => 20)
string $sqlEnd SQL string appended at the end of the query. For example 'ORDER BY createdAt DESC'

Return values:

array|null

See

mixed|null selectValue( string $table , string $column , array $where , [ string $sqlEnd = '' ] )

Execute SELECT query and return a single value

Parameters:

string $table Table name without prefix
string $column Column name. For example 'id'.
array $where Conditional array. For example array('id' => 20)
string $sqlEnd SQL string appended at the end of the query. For example 'ORDER BY createdAt DESC'

Return values:

mixed|null

See

selectColumn( mixed $table , mixed $column , mixed $where , [ mixed $sqlEnd = '' ] )
integer execute( string $sql , [ array $params = array() ] )

Execute SQL query

Parameters:

string $sql
array $params

Return values:

integer The number of rows affected by the last SQL statement

Throws:

Ip\Exception\Db
array fetchColumn( string $sql , [ array $params = array() ] )

Execute SQL query and return a result set

Parameters:

string $sql query
array $params The array represents each row as either an array of column values.

Return values:

array

Throws:

Ip\Exception\Db
boolean|string insert( mixed $table , mixed $row , [ boolean $ignore = false ] )

Execute query, insert values from associative array

Parameters:

mixed $table
mixed $row
boolean $ignore

Return values:

boolean|string
integer delete( string $table , array $condition )

Delete rows from a table

Parameters:

string $table
array $condition A condition, for example, array("userId" => 5, "card_id" => 8)

Return values:

integer count of rows affected
integer update( string $table , array $update , array|integer $condition )

Update table records

Execute query, updates values from associative array

Parameters:

string $table
array $update
array|integer $condition

Return values:

integer count of rows updated
upsert( string $table , array $keys , array $values )

insert or update row of $table identified by $keys with $values

Parameters:

string $table
array $keys
array $values
mixed tablePrefix( )

Return table prefix

Return values:

mixed
boolean isConnected( )

Get connection status

Return values:

boolean
getDriverName( )

Return name of current driver

boolean isSQLite( )

Return true if database is sqlite

Return values:

boolean
boolean isMySQL( )

Return true if database is mysql

Return values:

boolean
string sqlMinAge( string $fieldName , integer $minAge , [ string $unit = 'HOUR' ] )

Return SQL condition to select rows with minimum age (database-dependent)

Parameters:

string $fieldName field to compare
integer $minAge minimum age
string $unit unit for age (HOUR or MINUTE)

Return values:

string sql condition
string sqlMaxAge( string $fieldName , integer $maxAge , [ string $unit = 'HOUR' ] )

Return SQL condition to select rows with minimum age (database-dependent)

Parameters:

string $fieldName field to compare
integer $maxAge minimum age
string $unit unit for age (HOUR or MINUTE)

Return values:

string sql condition
comments powered by Disqus