PHP Class MysqliDb, PHP-MySQLi-Database-Class

Afficher le fichier Open project: joshcam/PHP-MySQLi-Database-Class Class Usage Examples

Méthodes publiques

Свойство 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

Свойство 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

Méthodes publiques

Méthode 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

Méthodes protégées

Méthode 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

Méthode 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 méthode

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 méthode

Close connection
public __destruct ( ) : void
Résultat void

_bindParam() protected méthode

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

_bindParams() protected méthode

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

_buildCondition() protected méthode

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

_buildDataPairs() public méthode

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

_buildGroupBy() protected méthode

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

_buildInsertQuery() protected méthode

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

_buildJoin() protected méthode

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

_buildJoinOld() protected méthode

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

_buildLimit() protected méthode

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
Résultat void

_buildOnDuplicate() protected méthode

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

_buildOrderBy() protected méthode

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

_buildPair() protected méthode

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
Résultat string

_buildQuery() protected méthode

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.
Résultat mysqli_stmt Returns the $stmt object.

_determineType() protected méthode

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.
Résultat string The joined parameter types.

_dynamicBindResults() protected méthode

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.
Résultat array The results of the SQL fetch.

_prepareQuery() protected méthode

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

_transaction_status_check() public méthode

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

arrayBuilder() public méthode

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

commit() public méthode

Transaction commit
public commit ( )

connect() public méthode

A method to connect to the database
public connect ( ) : void
Résultat void

copy() public méthode

Method returns a copy of a mysqlidb subquery object
public copy ( ) : MysqliDb
Résultat MysqliDb new mysqlidb object

dec() public méthode

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

delete() public méthode

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
Résultat boolean Indicates success. 0 or 1.

escape() public méthode

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

func() public méthode

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

get() public méthode

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
Résultat array Contains the returned rows from the select query.

getInsertId() public méthode

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

getInstance() public static méthode

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

getLastErrno() public méthode

Method returns mysql error code
public getLastErrno ( ) : integer
Résultat integer

getLastError() public méthode

Method returns mysql error
public getLastError ( ) : string
Résultat string

getLastQuery() public méthode

Method returns last executed query
public getLastQuery ( ) : string
Résultat string

getOne() public méthode

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
Résultat array Contains the returned rows from the select query.

getSubQuery() public méthode

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

getValue() public méthode

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
Résultat mixed Contains the value of a returned column / array of values

groupBy() public méthode

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.
Résultat MysqliDb

has() public méthode

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.
Résultat array Contains the returned rows from the select query.

having() public méthode

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 =
Résultat MysqliDb

inc() public méthode

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

insert() public méthode

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.
Résultat boolean Boolean indicating whether the insert query was completed succesfully.

insertMulti() public méthode

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.
Résultat boolean | array Boolean indicating the insertion failed (false), else return id-array ([int])

interval() public méthode

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
Résultat string

join() public méthode

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.
Résultat MysqliDb

joinOrWhere() public méthode

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.
Résultat dbWrapper

joinWhere() public méthode

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.
Résultat dbWrapper

jsonBuilder() public méthode

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

loadData() public méthode

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
Résultat boolean

loadXml() public méthode

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
Résultat boolean Returns true if the import succeeded, false if it failed.

lock() public méthode

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.
Résultat MysqliDb if succeeeded;

map() public méthode

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
Résultat MysqliDb

mysqli() public méthode

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

not() public méthode

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

now() public méthode

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
Résultat array

objectBuilder() public méthode

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

onDuplicate() public méthode

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
Résultat MysqliDb

orHaving() public méthode

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 =
Résultat MysqliDb

orWhere() public méthode

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 =
Résultat MysqliDb

orderBy() public méthode

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
Résultat MysqliDb

paginate() public méthode

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
Résultat array

ping() public méthode

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
Résultat boolean True if connection is up

query() public méthode

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)
Résultat array Contains the returned rows from the query.

rawQuery() public méthode

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.
Résultat array Contains the returned rows from the query.

rawQueryOne() public méthode

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.
Résultat array | null Contains the returned row from the query.

rawQueryValue() public méthode

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.
Résultat mixed Contains the returned rows from the query.

refValues() protected méthode

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

replace() public méthode

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.
Résultat boolean Boolean indicating whether the insert query was completed succesfully.

replacePlaceHolders() protected méthode

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

reset() protected méthode

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

rollback() public méthode

Transaction rollback function
public rollback ( )

setLockMethod() public méthode

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.
Résultat MysqliDb

setPrefix() public méthode

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

setQueryOption() public méthode

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.
Résultat MysqliDb

setTrace() public méthode

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
Résultat MysqliDb

startTransaction() public méthode

Begin a transaction
public startTransaction ( )

subQuery() public static méthode

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

tableExists() public méthode

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
Résultat boolean True if table exists

unlock() public méthode

Also commits transactions.
Author: Jonas Barascu
public unlock ( ) : MysqliDb
Résultat MysqliDb

update() public méthode

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.
Résultat boolean

where() public méthode

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)
Résultat MysqliDb

withTotalCount() public méthode

Function to enable SQL_CALC_FOUND_ROWS in the get queries
public withTotalCount ( ) : MysqliDb
Résultat 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
Résultat array

$_forUpdate protected_oe property

FOR UPDATE flag
protected bool $_forUpdate
Résultat boolean

$_groupBy protected_oe property

Dynamic type list for group by condition value
protected array $_groupBy
Résultat array

$_having protected_oe property

An array that holds having conditions
protected array $_having
Résultat array

$_instance protected_oe static_oe property

Static instance of self
protected static MysqliDb $_instance
Résultat MysqliDb

$_join protected_oe property

An array that holds where joins
protected array $_join
Résultat array

$_joinAnd protected_oe property

An array that holds where join ands
protected array $_joinAnd
Résultat array

$_lastInsertId protected_oe property

Name of the auto increment column
protected int $_lastInsertId
Résultat integer

$_lastQuery protected_oe property

The previously executed SQL query
protected string $_lastQuery
Résultat string

$_lockInShareMode protected_oe property

LOCK IN SHARE MODE flag
protected bool $_lockInShareMode
Résultat boolean

$_mapKey protected_oe property

Key field for Map()'ed result array
protected string $_mapKey
Résultat string

$_mysqli protected_oe property

MySQLi instance
protected mysqli $_mysqli
Résultat mysqli

$_nestJoin protected_oe property

Should join() results be nested by table
protected bool $_nestJoin
Résultat boolean

$_orderBy protected_oe property

Dynamic type list for order by condition value
protected array $_orderBy
Résultat array

$_query protected_oe property

The SQL query to be prepared and executed
protected string $_query
Résultat string

$_queryOptions protected_oe property

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

$_stmtErrno protected_oe property

Variable which holds last statement error code
protected int $_stmtErrno
Résultat integer

$_stmtError protected_oe property

Variable which holds last statement error
protected string $_stmtError
Résultat string

$_tableLockMethod protected_oe property

Variable which holds the current table lock method.
protected string $_tableLockMethod
Résultat string

$_tableLocks protected_oe property

Dynamic type list for tempromary locking tables.
protected array $_tableLocks
Résultat array

$_updateColumns protected_oe property

Column names for update when using onDuplicate method
protected array $_updateColumns
Résultat array

$_where protected_oe property

An array that holds where conditions
protected array $_where
Résultat 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
Résultat string

$db protected_oe property

protected $db

$host protected_oe property

Database credentials
protected string $host
Résultat string

$isSubQuery protected_oe property

Is Subquery object
protected bool $isSubQuery
Résultat boolean

$pageLimit public_oe property

Per page limit for pagination
public int $pageLimit
Résultat 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
Résultat string

$returnType public_oe property

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

$totalCount public_oe property

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

$totalPages public_oe property

Variable that holds total pages count of last paginate() query
public int $totalPages
Résultat 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