PHP Class MysqliDb, PHP-MySQLi-Database-Class

ファイルを表示 Open project: joshcam/PHP-MySQLi-Database-Class Class Usage Examples

Public Properties

Property Type Description
$count string Variable which holds an amount of returned rows during get/getOne/select queries
$pageLimit integer Per page limit for pagination
$prefix string Table prefix
$returnType string Return type: 'array' to return results as array, 'object' as object 'json' as json string
$totalCount string Variable which holds an amount of returned rows during get/getOne/select queries with withTotalCount()
$totalPages integer Variable that holds total pages count of last paginate() query
$trace

Protected Properties

Property Type Description
$_bindParams array Dynamic array that holds a combination of where condition/table data value types and parameter references
$_forUpdate boolean FOR UPDATE flag
$_groupBy array Dynamic type list for group by condition value
$_having array An array that holds having conditions
$_instance MysqliDb Static instance of self
$_join array An array that holds where joins
$_joinAnd array An array that holds where join ands
$_lastInsertId integer Name of the auto increment column
$_lastQuery string The previously executed SQL query
$_lockInShareMode boolean LOCK IN SHARE MODE flag
$_mapKey string Key field for Map()'ed result array
$_mysqli mysqli MySQLi instance
$_nestJoin boolean Should join() results be nested by table
$_orderBy array Dynamic type list for order by condition value
$_query string The SQL query to be prepared and executed
$_queryOptions string The SQL query options required after SELECT, INSERT, UPDATE or DELETE
$_stmtErrno integer Variable which holds last statement error code
$_stmtError string Variable which holds last statement error
$_tableLockMethod string Variable which holds the current table lock method.
$_tableLocks array Dynamic type list for tempromary locking tables.
$_updateColumns array Column names for update when using onDuplicate method
$_where array An array that holds where conditions
$charset
$db
$host string Database credentials
$isSubQuery boolean Is Subquery object
$password
$port
$traceEnabled
$traceStartQ Variables for query execution tracing
$traceStripPrefix
$username

Public Methods

Method Description
__construct ( string $host = null, string $username = null, string $password = null, string $db = null, integer $port = null, string $charset = 'utf8' )
__destruct ( ) : void Close connection
_buildDataPairs ( array $tableData, array $tableColumns, boolean $isInsert ) Insert/Update query helper
_transaction_status_check ( ) Shutdown handler to rollback uncommited operations in order to keep atomic operations sane.
arrayBuilder ( ) : MysqliDb Helper function to create dbObject with array return type Added for consistency as thats default output type
commit ( ) Transaction commit
connect ( ) : void A method to connect to the database
copy ( ) : MysqliDb Method returns a copy of a mysqlidb subquery object
dec ( integer $num = 1 ) : array Method generates decrimental function call
delete ( string $tableName, integer | array $numRows = null ) : boolean Delete query. Call the "where" method first.
escape ( string $str ) : string Escape harmful characters which might affect a query.
func ( string $expr, array $bindParams = null ) : array Method generates user defined function call
get ( string $tableName, integer | array $numRows = null, string $columns = '*' ) : array A convenient SELECT * function.
getInsertId ( ) : integer This methods returns the ID of the last inserted item
getInstance ( ) : MysqliDb A method of returning the static instance to allow access to the instantiated object from within another class.
getLastErrno ( ) : integer Method returns mysql error code
getLastError ( ) : string Method returns mysql error
getLastQuery ( ) : string Method returns last executed query
getOne ( string $tableName, string $columns = '*' ) : array A convenient SELECT * function to get one record.
getSubQuery ( ) : array Mostly internal method to get query and its params out of subquery object after get() and getAll()
getValue ( string $tableName, string $column, integer $limit = 1 ) : mixed A convenient SELECT COLUMN function to get a single column value from one row
groupBy ( string $groupByField ) : MysqliDb This method allows you to specify multiple (method chaining optional) GROUP BY statements for SQL queries.
has ( string $tableName ) : array A convenient function that returns TRUE if exists at least an element that satisfy the where condition specified calling the "where" method before this one.
having ( string $havingProp, mixed $havingValue = 'DBNULL', string $operator = '=', $cond = 'AND' ) : MysqliDb This method allows you to specify multiple (method chaining optional) AND HAVING statements for SQL queries.
inc ( integer $num = 1 ) : array Method generates incremental function call
insert ( string $tableName, array $insertData ) : boolean Insert method to add new row
insertMulti ( string $tableName, array $multiInsertData, array $dataKeys = null ) : boolean | array Insert method to add several rows at once
interval ( string $diff, string $func = "NOW()" ) : string Method returns generated interval function as a string
join ( string $joinTable, string $joinCondition, string $joinType = '' ) : MysqliDb This method allows you to concatenate joins for the final SQL statement.
joinOrWhere ( string $whereJoin, string $whereProp, mixed $whereValue = 'DBNULL', $operator = '=', $cond = 'AND' ) : dbWrapper This method allows you to specify multiple (method chaining optional) OR WHERE statements for the join table on part of the SQL query.
joinWhere ( string $whereJoin, string $whereProp, mixed $whereValue = 'DBNULL', $operator = '=', $cond = 'AND' ) : dbWrapper This method allows you to specify multiple (method chaining optional) AND WHERE statements for the join table on part of the SQL query.
jsonBuilder ( ) : MysqliDb Helper function to create dbObject with JSON return type
loadData ( string $importTable, string $importFile, string $importSettings = null ) : boolean This is a basic method which allows you to import raw .CSV data into a table Please check out http://dev.mysql.com/doc/refman/5.7/en/load-data.html for a valid .csv file.
loadXml ( string $importTable, string $importFile, string $importSettings = null ) : boolean This method is usefull for importing XML files into a specific table.
lock ( string $table ) : MysqliDb Locks a table for R/W action.
map ( string $idField ) : MysqliDb Return result as an associative array with $idField field value used as a record key
mysqli ( ) : mysqli A method to get mysqli object or create it in case needed
not ( string $col = null ) : array Method generates change boolean function call
now ( string $diff = null, string $func = "NOW()" ) : array Method returns generated interval function as an insert/update function
objectBuilder ( ) : MysqliDb Helper function to create dbObject with object return type.
onDuplicate ( array $updateColumns, string $lastInsertId = null ) : MysqliDb This function store update column's name and column name of the autoincrement column
orHaving ( string $havingProp, mixed $havingValue = null, string $operator = null ) : MysqliDb This method allows you to specify multiple (method chaining optional) OR HAVING statements for SQL queries.
orWhere ( string $whereProp, mixed $whereValue = 'DBNULL', string $operator = '=' ) : MysqliDb This method allows you to specify multiple (method chaining optional) OR WHERE statements for SQL queries.
orderBy ( string $orderByField, $orderbyDirection = "DESC", array $customFields = null ) : MysqliDb This method allows you to specify multiple (method chaining optional) ORDER BY statements for SQL queries.
paginate ( string $table, integer $page, array | string $fields = null ) : array Pagination wraper to get()
ping ( ) : boolean Method to call mysqli->ping() to keep unused connections open on long-running scripts, or to reconnect timed out connections (if php.ini has global mysqli.reconnect set to true). Can't do this directly using object since _mysqli is protected.
query ( string $query, integer | array $numRows = null ) : array A method to perform select query
rawQuery ( string $query, array $bindParams = null ) : array Execute raw SQL query.
rawQueryOne ( string $query, array $bindParams = null ) : array | null Helper function to execute raw SQL query and return only 1 row of results.
rawQueryValue ( string $query, array $bindParams = null ) : mixed Helper function to execute raw SQL query and return only 1 column of results.
replace ( string $tableName, array $insertData ) : boolean Replace method to add new row
rollback ( ) Transaction rollback function
setLockMethod ( string $method ) : MysqliDb This method sets the current table lock method.
setPrefix ( string $prefix = '' ) : MysqliDb Method to set a prefix
setQueryOption ( string | array $options ) : MysqliDb This method allows you to specify multiple (method chaining optional) options for SQL queries.
setTrace ( boolean $enabled, string $stripPrefix = null ) : MysqliDb Query exection time tracking switch
startTransaction ( ) Begin a transaction
subQuery ( string $subQueryAlias = "" ) : MysqliDb Method creates new mysqlidb object for a subquery generation
tableExists ( array $tables ) : boolean Method to check if needed table is created
unlock ( ) : MysqliDb Unlocks all tables in a database.
update ( string $tableName, array $tableData, integer $numRows = null ) : boolean Update query. Be sure to first call the "where" method.
where ( string $whereProp, mixed $whereValue = 'DBNULL', string $operator = '=', string $cond = 'AND' ) : MysqliDb This method allows you to specify multiple (method chaining optional) AND WHERE statements for SQL queries.
withTotalCount ( ) : MysqliDb Function to enable SQL_CALC_FOUND_ROWS in the get queries

Protected Methods

Method Description
_bindParam ( $value ) Helper function to add variables into bind parameters array
_bindParams ( array $values ) Helper function to add variables into bind parameters array in bulk
_buildCondition ( string $operator, array &$conditions ) Abstraction method that will build the part of the WHERE conditions
_buildGroupBy ( ) : void Abstraction method that will build the GROUP BY part of the WHERE statement
_buildInsertQuery ( array $tableData ) Abstraction method that will build an INSERT or UPDATE part of the query
_buildJoin ( ) Abstraction method that will build an JOIN part of the query
_buildJoinOld ( ) : void Abstraction method that will build an JOIN part of the query
_buildLimit ( integer | array $numRows ) : void Abstraction method that will build the LIMIT part of the WHERE statement
_buildOnDuplicate ( array $tableData ) Helper function to add variables into the query statement
_buildOrderBy ( ) : void Abstraction method that will build the LIMIT part of the WHERE statement
_buildPair ( string $operator, mixed $value ) : string Helper function to add variables into bind parameters array and will return its SQL part of the query according to operator in ' $operator ?' or ' $operator ($subquery) ' formats
_buildQuery ( integer | array $numRows = null, array $tableData = null ) : mysqli_stmt Abstraction method that will compile the WHERE statement, any passed update data, and the desired rows.
_determineType ( mixed $item ) : string This method is needed for prepared statements. They require the data type of the field to be bound with "i" s", etc.
_dynamicBindResults ( mysqli_stmt $stmt ) : array This helper method takes care of prepared statements' "bind_result method , when the number of variables to pass is unknown.
_prepareQuery ( ) : mysqli_stmt Method attempts to prepare the SQL query and throws an error if there was a problem.
refValues ( array &$arr ) : array Referenced data array is required by mysqli since PHP 5.3+
replacePlaceHolders ( string $str, array $vals ) : string Function to replace ? with variables from bind variable
reset ( ) : MysqliDb Reset states after an execution

Private Methods

Method Description
_buildInsert ( string $tableName, array $insertData, string $operation ) : boolean Internal function to build and execute INSERT/REPLACE calls
_traceGetCaller ( ) : string Get where and what function was called for query stored in MysqliDB->trace
conditionToSql ( String $operator, String $val ) Convert a condition and value into the sql string
queryUnprepared ( [[Type]] $query ) Pushes a unprepared statement to the mysqli stack.

Method Details

__construct() public method

public __construct ( string $host = null, string $username = null, string $password = null, string $db = null, integer $port = null, string $charset = 'utf8' )
$host string
$username string
$password string
$db string
$port integer
$charset string

__destruct() public method

Close connection
public __destruct ( ) : void
return void

_bindParam() protected method

Helper function to add variables into bind parameters array
protected _bindParam ( $value )

_bindParams() protected method

Helper function to add variables into bind parameters array in bulk
protected _bindParams ( array $values )
$values array Variable with values

_buildCondition() protected method

Abstraction method that will build the part of the WHERE conditions
protected _buildCondition ( string $operator, array &$conditions )
$operator string
$conditions array

_buildDataPairs() public method

Insert/Update query helper
public _buildDataPairs ( array $tableData, array $tableColumns, boolean $isInsert )
$tableData array
$tableColumns array
$isInsert boolean INSERT operation flag

_buildGroupBy() protected method

Abstraction method that will build the GROUP BY part of the WHERE statement
protected _buildGroupBy ( ) : void
return void

_buildInsertQuery() protected method

Abstraction method that will build an INSERT or UPDATE part of the query
protected _buildInsertQuery ( array $tableData )
$tableData array

_buildJoin() protected method

Abstraction method that will build an JOIN part of the query
protected _buildJoin ( )

_buildJoinOld() protected method

Abstraction method that will build an JOIN part of the query
protected _buildJoinOld ( ) : void
return void

_buildLimit() protected method

Abstraction method that will build the LIMIT part of the WHERE statement
protected _buildLimit ( integer | array $numRows ) : void
$numRows integer | array Array to define SQL limit in format Array ($count, $offset) or only $count
return void

_buildOnDuplicate() protected method

Helper function to add variables into the query statement
protected _buildOnDuplicate ( array $tableData )
$tableData array Variable with values

_buildOrderBy() protected method

Abstraction method that will build the LIMIT part of the WHERE statement
protected _buildOrderBy ( ) : void
return void

_buildPair() protected method

Helper function to add variables into bind parameters array and will return its SQL part of the query according to operator in ' $operator ?' or ' $operator ($subquery) ' formats
protected _buildPair ( string $operator, mixed $value ) : string
$operator string
$value mixed Variable with values
return string

_buildQuery() protected method

It then builds the SQL query.
protected _buildQuery ( integer | array $numRows = null, array $tableData = null ) : mysqli_stmt
$numRows integer | array Array to define SQL limit in format Array ($count, $offset) or only $count
$tableData array Should contain an array of data for updating the database.
return mysqli_stmt Returns the $stmt object.

_determineType() protected method

This function takes the input, determines what type it is, and then updates the param_type.
protected _determineType ( mixed $item ) : string
$item mixed Input to determine the type.
return string The joined parameter types.

_dynamicBindResults() protected method

This helper method takes care of prepared statements' "bind_result method , when the number of variables to pass is unknown.
protected _dynamicBindResults ( mysqli_stmt $stmt ) : array
$stmt mysqli_stmt Equal to the prepared statement object.
return array The results of the SQL fetch.

_prepareQuery() protected method

Method attempts to prepare the SQL query and throws an error if there was a problem.
protected _prepareQuery ( ) : mysqli_stmt
return mysqli_stmt

_transaction_status_check() public method

Shutdown handler to rollback uncommited operations in order to keep atomic operations sane.

arrayBuilder() public method

Helper function to create dbObject with array return type Added for consistency as thats default output type
public arrayBuilder ( ) : MysqliDb
return MysqliDb

commit() public method

Transaction commit
public commit ( )

connect() public method

A method to connect to the database
public connect ( ) : void
return void

copy() public method

Method returns a copy of a mysqlidb subquery object
public copy ( ) : MysqliDb
return MysqliDb new mysqlidb object

dec() public method

Method generates decrimental function call
public dec ( integer $num = 1 ) : array
$num integer increment by int or float. 1 by default
return array

delete() public method

Delete query. Call the "where" method first.
public delete ( string $tableName, integer | array $numRows = null ) : boolean
$tableName string The name of the database table to work with.
$numRows integer | array Array to define SQL limit in format Array ($count, $offset) or only $count
return boolean Indicates success. 0 or 1.

escape() public method

Escape harmful characters which might affect a query.
public escape ( string $str ) : string
$str string The string to escape.
return string The escaped string.

func() public method

Method generates user defined function call
public func ( string $expr, array $bindParams = null ) : array
$expr string user function body
$bindParams array
return array

get() public method

A convenient SELECT * function.
public get ( string $tableName, integer | array $numRows = null, string $columns = '*' ) : array
$tableName string The name of the database table to work with.
$numRows integer | array Array to define SQL limit in format Array ($count, $offset) or only $count
$columns string Desired columns
return array Contains the returned rows from the select query.

getInsertId() public method

This methods returns the ID of the last inserted item
public getInsertId ( ) : integer
return integer The last inserted item ID.

getInstance() public static method

Inheriting this class would require reloading connection info.
public static getInstance ( ) : MysqliDb
return MysqliDb Returns the current instance.

getLastErrno() public method

Method returns mysql error code
public getLastErrno ( ) : integer
return integer

getLastError() public method

Method returns mysql error
public getLastError ( ) : string
return string

getLastQuery() public method

Method returns last executed query
public getLastQuery ( ) : string
return string

getOne() public method

A convenient SELECT * function to get one record.
public getOne ( string $tableName, string $columns = '*' ) : array
$tableName string The name of the database table to work with.
$columns string Desired columns
return array Contains the returned rows from the select query.

getSubQuery() public method

Mostly internal method to get query and its params out of subquery object after get() and getAll()
public getSubQuery ( ) : array
return array

getValue() public method

A convenient SELECT COLUMN function to get a single column value from one row
public getValue ( string $tableName, string $column, integer $limit = 1 ) : mixed
$tableName string The name of the database table to work with.
$column string The desired column
$limit integer Limit of rows to select. Use null for unlimited..1 by default
return mixed Contains the value of a returned column / array of values

groupBy() public method

This method allows you to specify multiple (method chaining optional) GROUP BY statements for SQL queries.
public groupBy ( string $groupByField ) : MysqliDb
$groupByField string The name of the database field.
return MysqliDb

has() public method

A convenient function that returns TRUE if exists at least an element that satisfy the where condition specified calling the "where" method before this one.
public has ( string $tableName ) : array
$tableName string The name of the database table to work with.
return array Contains the returned rows from the select query.

having() public method

This method allows you to specify multiple (method chaining optional) AND HAVING statements for SQL queries.
public having ( string $havingProp, mixed $havingValue = 'DBNULL', string $operator = '=', $cond = 'AND' ) : MysqliDb
$havingProp string The name of the database field.
$havingValue mixed The value of the database field.
$operator string Comparison operator. Default is =
return MysqliDb

inc() public method

Method generates incremental function call
public inc ( integer $num = 1 ) : array
$num integer increment by int or float. 1 by default
return array

insert() public method

Insert method to add new row
public insert ( string $tableName, array $insertData ) : boolean
$tableName string The name of the table.
$insertData array Data containing information for inserting into the DB.
return boolean Boolean indicating whether the insert query was completed succesfully.

insertMulti() public method

Insert method to add several rows at once
public insertMulti ( string $tableName, array $multiInsertData, array $dataKeys = null ) : boolean | array
$tableName string The name of the table.
$multiInsertData array Two-dimensinal Data-array containing information for inserting into the DB.
$dataKeys array Optinal Table Key names, if not set in insertDataSet.
return boolean | array Boolean indicating the insertion failed (false), else return id-array ([int])

interval() public method

Method returns generated interval function as a string
public interval ( string $diff, string $func = "NOW()" ) : string
$diff string interval in the formats: "1", "-1d" or "- 1 day" -- For interval - 1 day Supported intervals [s]econd, [m]inute, [h]hour, [d]day, [M]onth, [Y]ear Default null;
$func string Initial date
return string

join() public method

This method allows you to concatenate joins for the final SQL statement.
public join ( string $joinTable, string $joinCondition, string $joinType = '' ) : MysqliDb
$joinTable string The name of the table.
$joinCondition string the condition.
$joinType string 'LEFT', 'INNER' etc.
return MysqliDb

joinOrWhere() public method

This method allows you to specify multiple (method chaining optional) OR WHERE statements for the join table on part of the SQL query.
public joinOrWhere ( string $whereJoin, string $whereProp, mixed $whereValue = 'DBNULL', $operator = '=', $cond = 'AND' ) : dbWrapper
$whereJoin string The name of the table followed by its prefix.
$whereProp string The name of the database field.
$whereValue mixed The value of the database field.
return dbWrapper

joinWhere() public method

This method allows you to specify multiple (method chaining optional) AND WHERE statements for the join table on part of the SQL query.
public joinWhere ( string $whereJoin, string $whereProp, mixed $whereValue = 'DBNULL', $operator = '=', $cond = 'AND' ) : dbWrapper
$whereJoin string The name of the table followed by its prefix.
$whereProp string The name of the database field.
$whereValue mixed The value of the database field.
return dbWrapper

jsonBuilder() public method

Helper function to create dbObject with JSON return type
public jsonBuilder ( ) : MysqliDb
return MysqliDb

loadData() public method

This is a basic method which allows you to import raw .CSV data into a table Please check out http://dev.mysql.com/doc/refman/5.7/en/load-data.html for a valid .csv file.
Author: Jonas Barascu (Noneatme)
public loadData ( string $importTable, string $importFile, string $importSettings = null ) : boolean
$importTable string The database table where the data will be imported into.
$importFile string The file to be imported. Please use double backslashes \\ and make sure you
$importSettings string An Array defining the import settings as described in the README.md
return boolean

loadXml() public method

Check out the LOAD XML syntax for your MySQL server.
Author: Jonas Barascu
public loadXml ( string $importTable, string $importFile, string $importSettings = null ) : boolean
$importTable string The table in which the data will be imported to.
$importFile string The file which contains the .XML data.
$importSettings string An Array defining the import settings as described in the README.md
return boolean Returns true if the import succeeded, false if it failed.

lock() public method

Locks a table for R/W action.
Author: Jonas Barascu
public lock ( string $table ) : MysqliDb
$table string The table to be locked. Can be a table or a view.
return MysqliDb if succeeeded;

map() public method

Array Returns an array($k => $v) if get(.."param1, param2"), array ($k => array ($v, $v)) otherwise
public map ( string $idField ) : MysqliDb
$idField string field name to use for a mapped element key
return MysqliDb

mysqli() public method

A method to get mysqli object or create it in case needed
public mysqli ( ) : mysqli
return mysqli

not() public method

Method generates change boolean function call
public not ( string $col = null ) : array
$col string column name. null by default
return array

now() public method

Method returns generated interval function as an insert/update function
public now ( string $diff = null, string $func = "NOW()" ) : array
$diff string interval in the formats: "1", "-1d" or "- 1 day" -- For interval - 1 day Supported intervals [s]econd, [m]inute, [h]hour, [d]day, [M]onth, [Y]ear Default null;
$func string Initial date
return array

objectBuilder() public method

Helper function to create dbObject with object return type.
public objectBuilder ( ) : MysqliDb
return MysqliDb

onDuplicate() public method

This function store update column's name and column name of the autoincrement column
public onDuplicate ( array $updateColumns, string $lastInsertId = null ) : MysqliDb
$updateColumns array Variable with values
$lastInsertId string Variable value
return MysqliDb

orHaving() public method

This method allows you to specify multiple (method chaining optional) OR HAVING statements for SQL queries.
public orHaving ( string $havingProp, mixed $havingValue = null, string $operator = null ) : MysqliDb
$havingProp string The name of the database field.
$havingValue mixed The value of the database field.
$operator string Comparison operator. Default is =
return MysqliDb

orWhere() public method

This method allows you to specify multiple (method chaining optional) OR WHERE statements for SQL queries.
public orWhere ( string $whereProp, mixed $whereValue = 'DBNULL', string $operator = '=' ) : MysqliDb
$whereProp string The name of the database field.
$whereValue mixed The value of the database field.
$operator string Comparison operator. Default is =
return MysqliDb

orderBy() public method

This method allows you to specify multiple (method chaining optional) ORDER BY statements for SQL queries.
public orderBy ( string $orderByField, $orderbyDirection = "DESC", array $customFields = null ) : MysqliDb
$orderByField string The name of the database field.
$customFields array Fieldset for ORDER BY FIELD() ordering
return MysqliDb

paginate() public method

Pagination wraper to get()
public paginate ( string $table, integer $page, array | string $fields = null ) : array
$table string The name of the database table to work with
$page integer Page number
$fields array | string Array or coma separated list of fields to fetch
return array

ping() public method

Method to call mysqli->ping() to keep unused connections open on long-running scripts, or to reconnect timed out connections (if php.ini has global mysqli.reconnect set to true). Can't do this directly using object since _mysqli is protected.
public ping ( ) : boolean
return boolean True if connection is up

query() public method

A method to perform select query
public query ( string $query, integer | array $numRows = null ) : array
$query string Contains a user-provided select query.
$numRows integer | array Array to define SQL limit in format Array ($count, $offset)
return array Contains the returned rows from the query.

rawQuery() public method

Execute raw SQL query.
public rawQuery ( string $query, array $bindParams = null ) : array
$query string User-provided query to execute.
$bindParams array Variables array to bind to the SQL statement.
return array Contains the returned rows from the query.

rawQueryOne() public method

Note that function do not add 'limit 1' to the query by itself Same idea as getOne()
public rawQueryOne ( string $query, array $bindParams = null ) : array | null
$query string User-provided query to execute.
$bindParams array Variables array to bind to the SQL statement.
return array | null Contains the returned row from the query.

rawQueryValue() public method

If 'limit 1' will be found, then string will be returned instead of array Same idea as getValue()
public rawQueryValue ( string $query, array $bindParams = null ) : mixed
$query string User-provided query to execute.
$bindParams array Variables array to bind to the SQL statement.
return mixed Contains the returned rows from the query.

refValues() protected method

Referenced data array is required by mysqli since PHP 5.3+
protected refValues ( array &$arr ) : array
$arr array
return array

replace() public method

Replace method to add new row
public replace ( string $tableName, array $insertData ) : boolean
$tableName string The name of the table.
$insertData array Data containing information for inserting into the DB.
return boolean Boolean indicating whether the insert query was completed succesfully.

replacePlaceHolders() protected method

Function to replace ? with variables from bind variable
protected replacePlaceHolders ( string $str, array $vals ) : string
$str string
$vals array
return string

reset() protected method

Reset states after an execution
protected reset ( ) : MysqliDb
return MysqliDb Returns the current instance.

rollback() public method

Transaction rollback function
public rollback ( )

setLockMethod() public method

This method sets the current table lock method.
Author: Jonas Barascu
public setLockMethod ( string $method ) : MysqliDb
$method string The table lock method. Can be READ or WRITE.
return MysqliDb

setPrefix() public method

Method to set a prefix
public setPrefix ( string $prefix = '' ) : MysqliDb
$prefix string Contains a tableprefix
return MysqliDb

setQueryOption() public method

This method allows you to specify multiple (method chaining optional) options for SQL queries.
public setQueryOption ( string | array $options ) : MysqliDb
$options string | array The optons name of the query.
return MysqliDb

setTrace() public method

Query exection time tracking switch
public setTrace ( boolean $enabled, string $stripPrefix = null ) : MysqliDb
$enabled boolean Enable execution time tracking
$stripPrefix string Prefix to strip from the path in exec log
return MysqliDb

startTransaction() public method

Begin a transaction
public startTransaction ( )

subQuery() public static method

Method creates new mysqlidb object for a subquery generation
public static subQuery ( string $subQueryAlias = "" ) : MysqliDb
$subQueryAlias string
return MysqliDb

tableExists() public method

Method to check if needed table is created
public tableExists ( array $tables ) : boolean
$tables array Table name or an Array of table names to check
return boolean True if table exists

unlock() public method

Also commits transactions.
Author: Jonas Barascu
public unlock ( ) : MysqliDb
return MysqliDb

update() public method

Update query. Be sure to first call the "where" method.
public update ( string $tableName, array $tableData, integer $numRows = null ) : boolean
$tableName string The name of the database table to work with.
$tableData array Array of data to update the desired row.
$numRows integer Limit on the number of rows that can be updated.
return boolean

where() public method

This method allows you to specify multiple (method chaining optional) AND WHERE statements for SQL queries.
public where ( string $whereProp, mixed $whereValue = 'DBNULL', string $operator = '=', string $cond = 'AND' ) : MysqliDb
$whereProp string The name of the database field.
$whereValue mixed The value of the database field.
$operator string Comparison operator. Default is =
$cond string Condition of where statement (OR, AND)
return MysqliDb

withTotalCount() public method

Function to enable SQL_CALC_FOUND_ROWS in the get queries
public withTotalCount ( ) : MysqliDb
return MysqliDb

Property Details

$_bindParams protected_oe property

Dynamic array that holds a combination of where condition/table data value types and parameter references
protected array $_bindParams
return array

$_forUpdate protected_oe property

FOR UPDATE flag
protected bool $_forUpdate
return boolean

$_groupBy protected_oe property

Dynamic type list for group by condition value
protected array $_groupBy
return array

$_having protected_oe property

An array that holds having conditions
protected array $_having
return array

$_instance protected_oe static_oe property

Static instance of self
protected static MysqliDb $_instance
return MysqliDb

$_join protected_oe property

An array that holds where joins
protected array $_join
return array

$_joinAnd protected_oe property

An array that holds where join ands
protected array $_joinAnd
return array

$_lastInsertId protected_oe property

Name of the auto increment column
protected int $_lastInsertId
return integer

$_lastQuery protected_oe property

The previously executed SQL query
protected string $_lastQuery
return string

$_lockInShareMode protected_oe property

LOCK IN SHARE MODE flag
protected bool $_lockInShareMode
return boolean

$_mapKey protected_oe property

Key field for Map()'ed result array
protected string $_mapKey
return string

$_mysqli protected_oe property

MySQLi instance
protected mysqli $_mysqli
return mysqli

$_nestJoin protected_oe property

Should join() results be nested by table
protected bool $_nestJoin
return boolean

$_orderBy protected_oe property

Dynamic type list for order by condition value
protected array $_orderBy
return array

$_query protected_oe property

The SQL query to be prepared and executed
protected string $_query
return string

$_queryOptions protected_oe property

The SQL query options required after SELECT, INSERT, UPDATE or DELETE
protected string $_queryOptions
return string

$_stmtErrno protected_oe property

Variable which holds last statement error code
protected int $_stmtErrno
return integer

$_stmtError protected_oe property

Variable which holds last statement error
protected string $_stmtError
return string

$_tableLockMethod protected_oe property

Variable which holds the current table lock method.
protected string $_tableLockMethod
return string

$_tableLocks protected_oe property

Dynamic type list for tempromary locking tables.
protected array $_tableLocks
return array

$_updateColumns protected_oe property

Column names for update when using onDuplicate method
protected array $_updateColumns
return array

$_where protected_oe property

An array that holds where conditions
protected array $_where
return array

$charset protected_oe property

protected $charset

$count public_oe property

Variable which holds an amount of returned rows during get/getOne/select queries
public string $count
return string

$db protected_oe property

protected $db

$host protected_oe property

Database credentials
protected string $host
return string

$isSubQuery protected_oe property

Is Subquery object
protected bool $isSubQuery
return boolean

$pageLimit public_oe property

Per page limit for pagination
public int $pageLimit
return integer

$password protected_oe property

protected $password

$port protected_oe property

protected $port

$prefix public_oe static_oe property

Table prefix
public static string $prefix
return string

$returnType public_oe property

Return type: 'array' to return results as array, 'object' as object 'json' as json string
public string $returnType
return string

$totalCount public_oe property

Variable which holds an amount of returned rows during get/getOne/select queries with withTotalCount()
public string $totalCount
return string

$totalPages public_oe property

Variable that holds total pages count of last paginate() query
public int $totalPages
return integer

$trace public_oe property

public $trace

$traceEnabled protected_oe property

protected $traceEnabled

$traceStartQ protected_oe property

Variables for query execution tracing
protected $traceStartQ

$traceStripPrefix protected_oe property

protected $traceStripPrefix

$username protected_oe property

protected $username