Constants

PAGINATION_DEFAULT_ROWS

PAGINATION_DEFAULT_ROWS

PAGINATION_MAX_VISIBLE_PAGES

PAGINATION_MAX_VISIBLE_PAGES

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

$__db

$__db : 

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

init_db()

init_db() : \MyDB

Returns

\MyDB

intialize DB

isConnectionOK()

isConnectionOK(null  $host = NULL, null  $user = NULL, null  $password = NULL, null  $DB = NULL) 

Parameters

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

Check if we cant connect to mysql

db()

db() : boolean

Returns

boolean —

quick reference to ge DB object

getArrayValues()

getArrayValues(  $table,   $formPOSTS) : array

Parameters

$table
$formPOSTS

return all POST inputs name if exists on table

Returns

array

insertRecord()

insertRecord(  $tblName,   $knownTblNameFields,   $HtmlPostRecords) : \idOfnewRecord

Parameters

$tblName

DB Table ' Auth '

$knownTblNameFields

Structure of $tblName

$HtmlPostRecords

POST Array

insert new record on $tblName from $_POST $HtmlPostRecords with structure $knownTblNameFields

Returns

\idOfnewRecord

insertRecordUniqueField()

insertRecordUniqueField(  $tblName,   $knownTblNameFields,   $HtmlPostRecords) : \idOfnewRecord

Parameters

$tblName
$knownTblNameFields
$HtmlPostRecords

insert new record on $tblName from $_POST $HtmlPostRecords with structure $knownTblNameFields WHERE $HtmlPostRecords['name'] is UNIQUE

Use for linked tables, foreign keys to primary, vice versa

DB Design field must by UQ :

Returns

\idOfnewRecord

description()

description(  $table) : mixed

Parameters

$table

Returns

mixed —

describe Fields on tbl

show_tables()

show_tables() : mixed

Returns

mixed —

Mysql get all tables from DB

show_table_status()

show_table_status() : array

Returns

array —

return table Status

optimize_table()

optimize_table(  $table) : mixed

Parameters

$table

Returns

mixed —

optimize table not innodb

stats()

stats() : array

Returns

array —

get DB Server status

pagination()

pagination(  $sql,   $sql_params,   $navigation,   $_link_pagination, integer  $current_page = 1) : array

Parameters

$sql
$sql_params
$navigation
$_link_pagination
integer $current_page

Pagination SQL with rawQuery

Returns

array

stringNormalise()

stringNormalise(  $string) : string

normalise strings

Parameters

$string

Returns

string

objectToArray()

objectToArray(  $d) : array

Parameters

$d

return any object to array

convert INPUT object to Array

Returns

array

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.