Properties

$Host

$Host : 

Security Tip

MySQL User SQL_USER must only have access : SELECT , INSERT, UPDATE, execute stored procedures

 UPDATE : to other user ?

Type

$Database

$Database : 

Type

$User

$User : 

Type

$Password

$Password : 

Type

$_last_insert_id

$_last_insert_id : 

Type

$_lastStmtError

$_lastStmtError : 

Type

$_instance

$_instance : 

Type

$_mysqli

$_mysqli : object

MySQLi instance

Type

object

$_query

$_query : object

The SQL query to be prepared and executed

Type

object

$_where

$_where : array

An array that holds where conditions 'fieldname' => 'value'

Type

array

$_whereTypeList

$_whereTypeList : array

Dynamic type list for where condition values

Type

array

$_paramTypeList

$_paramTypeList : array

Dynamic type list for table data values

Type

array

$_bindParams

$_bindParams : array

Dynamic array that holds a combination of where condition/table data value types and parameter referances

Type

array

$transaction_in_progress

$transaction_in_progress : 

Type

Methods

__construct()

__construct() 

halt()

halt(string  $msg = "") 

Parameters

string $msg

display Error and die()

checkCredentials()

checkCredentials(null  $host = NULL, null  $user = NULL, null  $password = NULL, null  $DB = NULL) : boolean

Parameters

null $host
null $user
null $password
null $DB

Returns

boolean —

check if given Credentials is correct via configuration.php

getInstance()

getInstance() : object

A method of returning the static instance to allow access to the instantiated object from within another class.

Inheriting this class would require reloading connection info.

Returns

object —

Returns the current instance.

change_db()

change_db(  $dbname) 

Parameters

$dbname

get_dbname()

get_dbname() 

sql()

sql(  $query,   $wherearray = NULL) 

Parameters

$query
$wherearray

next_record()

next_record() 

rawQuery()

rawQuery(string  $query,   $bindParams = NULL) : array

Pass in a raw query and an array containing the parameters to bind to the prepaird statement.

Parameters

string $query

Contains a user-provided query.

$bindParams

Returns

array —

Contains the returned rows from the query.

query()

query(string  $query, integer  $numRows = NULL) : array

Parameters

string $query

Contains a user-provided select query.

integer $numRows

The number of rows total to return.

Returns

array —

Contains the returned rows from the query.

get()

get(string  $tableName, integer  $numRows = NULL) : array

A convenient SELECT * function.

Parameters

string $tableName

The name of the database table to work with.

integer $numRows

The number of rows total to return.

Returns

array —

Contains the returned rows from the select query.

insert()

insert(\<string  $tableName, array  $insertData) : boolean

Parameters

\ $tableName

The name of the table.

array $insertData

Data containing information for inserting into the DB.

Returns

boolean —

Boolean indicating whether the insert query was completed succesfully.

update()

update(string  $tableName, array  $tableData) : boolean

Update query. Be sure to first call the "where" method.

Parameters

string $tableName

The name of the database table to work with.

array $tableData

Array of data to update the desired row.

Returns

boolean

delete()

delete(string  $tableName, integer  $numRows = NULL) : boolean

Delete query. Call the "where" method first.

Parameters

string $tableName

The name of the database table to work with.

integer $numRows

The number of rows to delete.

Returns

boolean —

Indicates success. 0 or 1.

where()

where(string  $whereProp, mixed  $whereValue) 

This method allows you to specify multipl (method chaining optional) WHERE statements for SQL queries.

Parameters

string $whereProp

The name of the database field.

mixed $whereValue

The value of the database field.

__destruct()

__destruct() 

close()

close() 

autocommit()

autocommit(boolean  $mode = FALSE) : boolean

set autocommit for transcation processing mysqli_autocommit | mysqli::autocommit

Parameters

boolean $mode

Returns

boolean

commit()

commit() : boolean

commit mysqli_commit | mysqli::commit

Returns

boolean

rollback()

rollback() : boolean

rollback mysqli_rollback | mysqli::rollback

Returns

boolean

lock()

lock(  $tablename,   $lock_type = "WRITE") 

Parameters

$tablename
$lock_type

unlock()

unlock() : boolean

unlock

Returns

boolean

error()

error() 

get_last_id()

get_last_id() 

transaction()

transaction() 

mysqli__shutdown_check()

mysqli__shutdown_check() 

transaction_isolcation_level()

transaction_isolcation_level(  $level = "REPEATABLE READ") 

Parameters

$level

procedure()

procedure(  $name) 

Parameters

$name

reset()

reset() : object

Reset states after an execution

Returns

object —

Returns the current instance.

_determineType()

_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.

This function takes the input, determines what type it is, and then updates the param_type.

Parameters

mixed $item

Input to determine the type.

Returns

string —

The joined parameter types.

_buildQuery()

_buildQuery(integer  $numRows = NULL, array  $tableData = NULL) : object

Abstraction method that will compile the WHERE statement, any passed update data, and the desired rows.

It then builds the SQL query.

Parameters

integer $numRows

The number of rows total to return.

array $tableData

Should contain an array of data for updating the database.

Returns

object —

Returns the $stmt object.

_dynamicBindResults()

_dynamicBindResults(object  $stmt) : array

This helper method takes care of prepared statements' "bind_result method , when the number of variables to pass is unknown.

Parameters

object $stmt

Equal to the prepared statement object.

Returns

array —

The results of the SQL fetch.

_prepareQuery()

_prepareQuery() 

Method attempts to prepare the SQL query and throws an error if there was a problem.