PHP Interface iaInterfaceDbAdapter

Subrion - open source content management system Copyright (C) 2016 Intelliants, LLC This file is part of Subrion. Subrion is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Subrion is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Subrion. If not, see .
Show file Open project: intelliants/subrion

Public Methods

Method Description
all ( string $fields = self::ALL_COLUMNS_SELECTION, string $condition = '', integer $start, integer | null $limit = null, string | null $tableName = null ) : array Returns table rows as array
assoc ( string $fields = self::ALL_COLUMNS_SELECTION, string $condition = '', string | null $tableName = null, integer $start, integer | null $limit = null ) : array Returns associative array of rows, first column of the query is used as a key
bind ( string &$sql, array $values ) : void Binds queries to make SQL more readable
cascadeDelete ( string | array $tbl, string $where = '' ) : boolean | integer Accepts array of table names and deletes records in them
convertIds ( array | string | integer $ids, string $columnName = 'id', boolean $equal = true ) : boolean | string Converts various condition params to a mysql formatted WHERE case string
delete ( string $condition, string | null $tableName = null, array $values = [] ) : integer Deletes records in a table and returns number of affected rows by the query
describe ( null $tableName = null, boolean $addPrefix = true ) : array Provides information about the columns in a table
exists ( string $where, array $values = [], null $tableName = null ) : boolean Returns true if at least 1 record exists
foundRows ( ) : integer Returns number of found rows of the previous query with SQL_CALC_FOUND_ROWS Note: this SQL function is MySQL specific
getAffected ( ) : integer Returns a number of affected rows in a previous INSERT operation
getAll ( string $sql, integer $start, integer $limit ) : array Returns table rows as array
getAssoc ( string $sql, boolean $singleRow = false ) : array Returns associative array of rows, first column of the query is used as a key
getCount ( ) : integer Returns number of queries
getEnumValues ( string $table, string $field ) : array | boolean Returns all ENUM and SET values for selected table and field
getErrorNumber ( ) : integer Returns the numerical value of the error message from previous database operation
getInsertId ( ) : integer Returns the ID generated in the last query
getKeyValue ( string $sql ) : array Returns key => value pair array of rows
getLastQuery ( ) : string Returns last executed query
getMaxOrder ( string $table = null, array $condition = null ) : boolean | mixed Returns max value for order column
getNumRows ( resource $resource ) : integer Returns a number of rows in a result
getOne ( string $sql ) : mixed Returns field value of a row
getPrefix ( ) : string Returns table prefix value
getQueriesList ( ) : array Returns list of executed queries
getRow ( string $sql ) : array | boolean Returns one table row as array
insert ( array $values, array | null $rawValues = null, string | null $tableName = null ) : integer Inserts a new record in a table and returns id of the inserted row
keyvalue ( string $fields = self::ALL_COLUMNS_SELECTION, string $condition = null, string | null $tableName = null, integer $start, integer | null $limit = null ) : array Returns key => value pair array of rows
one ( string $field, string $condition = '', string | null $tableName = null, integer $start ) : boolean | mixed Returns field value of a row
one_bind ( string $field, string $condition, array $values, null $tableName = null, integer $start ) : array Returns one field value on binding completion
onefield ( string $field = self::ID_COLUMN_SELECTION, string $condition = null, integer $start, integer | null $limit = null, string | null $tableName = null ) : array Returns table column values as an array
orderByRand ( integer | string $max, string $id_name = '`id`', integer $pieces = 12, integer $delimiter = 100 ) : mixed Generates a faster way to select random records
printf ( string $pattern, array $replacements ) : string Returns a formatted string according to replacements Does NOT sanitize any input (!)
query ( string $sql ) : resource Executes database query
replace ( array $values, array | null $rawValues = null, string | null $tableName = null ) : integer Replaces a record in a table
resetTable ( ) : void Resets table name to the previous state
row ( string $fields = self::ALL_COLUMNS_SELECTION, string $condition = '', string | null $tableName = null, integer $start ) : array Returns one table row as array
row_bind ( string $fields, string $condition, array $values, null $tableName = null, integer $start ) : array Returns single row array on binding completion
setTable ( string $tableName, boolean $addPrefix = true ) : void Sets table to work with (in most cases resetTable should be called after calling this method)
setTimezoneOffset ( $offset )
truncate ( null | string $table = null ) : boolean Truncates table
update ( array $values, string $condition = null, array | null $rawValues = null, string | null $tableName = null ) : boolean | integer Updates a record in a table and returns a number of affected rows

Method Details

all() public method

Returns table rows as array
public all ( string $fields = self::ALL_COLUMNS_SELECTION, string $condition = '', integer $start, integer | null $limit = null, string | null $tableName = null ) : array
$fields string fields to be selected
$condition string condition for the selection
$start integer start position
$limit integer | null number of records to be returned
$tableName string | null table name to select records from, null uses current set table
return array

assoc() public method

Returns associative array of rows, first column of the query is used as a key
public assoc ( string $fields = self::ALL_COLUMNS_SELECTION, string $condition = '', string | null $tableName = null, integer $start, integer | null $limit = null ) : array
$fields string fields to be selected
$condition string condition for the selection
$tableName string | null table name to select records from, null uses current set table
$start integer start position
$limit integer | null number of records to be returned
return array

bind() public method

Ex: $sql = "SELECT * FROM users WHERE user = :user AND password = :password"; mysqli_bind($sql, array('user' => $user, 'password' => $password)); mysqli_query($sql);
public bind ( string &$sql, array $values ) : void
$sql string sql query to be processed
$values array real values key=>value array to be replaced in sql query
return void

cascadeDelete() public method

Accepts array of table names and deletes records in them
public cascadeDelete ( string | array $tbl, string $where = '' ) : boolean | integer
$tbl string | array table name(s)
$where string sql condition to perform deletion
return boolean | integer

convertIds() public static method

Ex: $where = $iaCore->iaDb->convertIds('id', array('1', '3', '5', '6')); echo $where; // id = IN('1', '3', '5', '6')
public static convertIds ( array | string | integer $ids, string $columnName = 'id', boolean $equal = true ) : boolean | string
$ids array | string | integer
$columnName string field name
$equal boolean operand type
return boolean | string

delete() public method

Deletes records in a table and returns number of affected rows by the query
public delete ( string $condition, string | null $tableName = null, array $values = [] ) : integer
$condition string condition to perform deletion
$tableName string | null table name where to perform deletion, null - deletes currently set table
$values array real values key=>value array to be replaced in condition
return integer

describe() public method

Provides information about the columns in a table
public describe ( null $tableName = null, boolean $addPrefix = true ) : array
$tableName null table name
$addPrefix boolean avoid prefix addition if false
return array

exists() public method

Returns true if at least 1 record exists
public exists ( string $where, array $values = [], null $tableName = null ) : boolean
$where string condition
$values array
$tableName null table name
return boolean

foundRows() public method

Returns number of found rows of the previous query with SQL_CALC_FOUND_ROWS Note: this SQL function is MySQL specific
public foundRows ( ) : integer
return integer

getAffected() public method

Returns a number of affected rows in a previous INSERT operation
public getAffected ( ) : integer
return integer

getAll() public method

Returns table rows as array
public getAll ( string $sql, integer $start, integer $limit ) : array
$sql string sql query
$start integer start position
$limit integer number of rows to be returned
return array

getAssoc() public method

Returns associative array of rows, first column of the query is used as a key
public getAssoc ( string $sql, boolean $singleRow = false ) : array
$sql string sql query
$singleRow boolean
return array

getCount() public method

Returns number of queries
public getCount ( ) : integer
return integer

getEnumValues() public method

Returns all ENUM and SET values for selected table and field
public getEnumValues ( string $table, string $field ) : array | boolean
$table string table name
$field string field name
return array | boolean

getErrorNumber() public method

Returns the numerical value of the error message from previous database operation
public getErrorNumber ( ) : integer
return integer

getInsertId() public method

Returns the ID generated in the last query
public getInsertId ( ) : integer
return integer

getKeyValue() public method

Returns key => value pair array of rows
public getKeyValue ( string $sql ) : array
$sql string sql query
return array

getLastQuery() public method

Returns last executed query
public getLastQuery ( ) : string
return string

getMaxOrder() public method

Returns max value for order column
public getMaxOrder ( string $table = null, array $condition = null ) : boolean | mixed
$table string table name
$condition array column name, value
return boolean | mixed

getNumRows() public method

Returns a number of rows in a result
public getNumRows ( resource $resource ) : integer
$resource resource query resource
return integer

getOne() public method

Returns field value of a row
public getOne ( string $sql ) : mixed
$sql string sql query
return mixed

getPrefix() public method

Returns table prefix value
public getPrefix ( ) : string
return string

getQueriesList() public method

Returns list of executed queries
public getQueriesList ( ) : array
return array

getRow() public method

Returns one table row as array
public getRow ( string $sql ) : array | boolean
$sql string sql query
return array | boolean

insert() public method

Ex: the code below inserts a new record in 'table_name' $iaCore->iaDb->insert(array('title' => 'My Row Title', 'text' => 'My Row Text'), array('date' => 'NOW()'), 'table_name'); generated sql code looks like: INSERT INTO prefix_table_name SET title = 'My Row Title', text = 'My Row Text', date = NOW();
public insert ( array $values, array | null $rawValues = null, string | null $tableName = null ) : integer
$values array key=>value array for the record
$rawValues array | null key=>value array for the record without sanitizing, commonly used for date insert
$tableName string | null table name to perform insertion, null uses current set table
return integer

keyvalue() public method

Returns key => value pair array of rows
public keyvalue ( string $fields = self::ALL_COLUMNS_SELECTION, string $condition = null, string | null $tableName = null, integer $start, integer | null $limit = null ) : array
$fields string fields to be selected
$condition string condition for the selection
$tableName string | null table name to select records from, null uses current set table
$start integer start position
$limit integer | null number of records to be returned
return array

one() public method

Returns field value of a row
public one ( string $field, string $condition = '', string | null $tableName = null, integer $start ) : boolean | mixed
$field string field to be selected
$condition string condition for the selection
$tableName string | null table name to select records from, null uses current set table
$start integer starting position
return boolean | mixed

one_bind() public method

Returns one field value on binding completion
public one_bind ( string $field, string $condition, array $values, null $tableName = null, integer $start ) : array
$field string field name value to be returned
$condition string condition to be used for the selection
$values array values key=>value array to be replaced in sql query
$tableName null table name to select a record from, null uses current set table
$start integer start position
return array

onefield() public method

Returns table column values as an array
public onefield ( string $field = self::ID_COLUMN_SELECTION, string $condition = null, integer $start, integer | null $limit = null, string | null $tableName = null ) : array
$field string field name column to be selected
$condition string condition for the selection
$start integer start position
$limit integer | null number of records to be returned
$tableName string | null table name to select records from, null uses current set table
return array

orderByRand() public method

Generates a faster way to select random records
public orderByRand ( integer | string $max, string $id_name = '`id`', integer $pieces = 12, integer $delimiter = 100 ) : mixed
$max integer | string max order or table name
$id_name string id column
$pieces integer
$delimiter integer
return mixed

printf() public static method

Returns a formatted string according to replacements Does NOT sanitize any input (!)
public static printf ( string $pattern, array $replacements ) : string
$pattern string replacement pattern
$replacements array new values
return string

query() public method

Executes database query
public query ( string $sql ) : resource
$sql string sql query to be executed
return resource

replace() public method

Ex: the code below inserts a new record in 'table_name' $iaCore->iaDb->insert(array('title' => 'My Row Title', 'text' => 'My Row Text'), array('date' => 'NOW()'), 'table_name'); generated sql code looks like: REPLACE INTO prefix_table_name SET title = 'My Row Title', text = 'My Row Text', date = NOW();
public replace ( array $values, array | null $rawValues = null, string | null $tableName = null ) : integer
$values array key=>value array for the record
$rawValues array | null key=>value array for the record without sanitizing, commonly used for date insert
$tableName string | null table name to perform insertion, null uses current set table
return integer

resetTable() public method

Resets table name to the previous state
public resetTable ( ) : void
return void

row() public method

Returns one table row as array
public row ( string $fields = self::ALL_COLUMNS_SELECTION, string $condition = '', string | null $tableName = null, integer $start ) : array
$fields string fields to be selected
$condition string condition for the selection
$tableName string | null table name to select records from, null uses current set table
$start integer start position
return array

row_bind() public method

Returns single row array on binding completion
public row_bind ( string $fields, string $condition, array $values, null $tableName = null, integer $start ) : array
$fields string fields to be returned
$condition string condition to be used for the selection
$values array values key=>value array to be replaced in sql query
$tableName null table name to select a record from, null uses current set table
$start integer start position
return array

setTable() public method

Sets table to work with (in most cases resetTable should be called after calling this method)
public setTable ( string $tableName, boolean $addPrefix = true ) : void
$tableName string table name
$addPrefix boolean true - adds prefix for the table name
return void

setTimezoneOffset() public method

public setTimezoneOffset ( $offset )

truncate() public method

Truncates table
public truncate ( null | string $table = null ) : boolean
$table null | string table name
return boolean

update() public method

Ex: the code below updates a record in 'table_name' $iaCore->iaDb->update(array('id' => '50', 'title' => 'My Row Title', 'text' => 'My Row Text'), null, array('date' => 'NOW()'), 'table_name'); generated sql code looks like: UPDATE prefix_table_name SET title = 'My Row Title', text = 'My Row Text', date = NOW() WHERE id = '50';
public update ( array $values, string $condition = null, array | null $rawValues = null, string | null $tableName = null ) : boolean | integer
$values array fields key=>value array to be updated
$condition string condition used for the update query, if empty tries to update using id field from $fields array
$rawValues array | null key=>value array for the record without sanitizing, commonly used for date insert
$tableName string | null table name to perform update, null uses current set table
return boolean | integer