Properties

$_queryResult

$_queryResult

$_instance

$_instance : \MysqliDb

Static instance of self

Type

\MysqliDb

$_mysqli

$_mysqli : \mysqli

MySQLi instance

Type

\mysqli

$_query

$_query : string

The SQL query to be prepared and executed

Type

string

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

$_orderBy

$_orderBy

Dynamic type list for order by condition value

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

$_email

$_email

$_valueToCheck

$_valueToCheck

Methods

publishComment()

publishComment( $userId,  $isLogged,  $isSentForm,  $newComment,  $bookId)

Parameters

$userId
$isLogged
$isSentForm
$newComment
$bookId

validate()

validate( $valueToCheck, int $minLength, \Models\str $errMsg, int $errCode) : \Models\int,

This method is to trim and validate data by minimum length.

Parameters

$valueToCheck
int $minLength
\Models\str $errMsg
int $errCode

Throws

\Exception

Returns

\Models\int, —

str

validateEmail()

validateEmail(\Models\str $email) : \Models\str

This method validates email.

Parameters

\Models\str $email

Throws

\Exception\

Returns

\Models\str

isInDb()

isInDb(\Models\str $tableName, \Models\str $columnName, \Models\str $valueToCheck) : int

This method is to check if value is in the DB. Returns number of affected rows.

Parameters

\Models\str $tableName
\Models\str $columnName
\Models\str $valueToCheck

Returns

int —
  • numbers of rows

registration()

registration(\Models\str $userName, \Models\str $password, \Models\str $email)

This method saves user in the DB.

Parameters

\Models\str $userName
\Models\str $password
\Models\str $email

Throws

\Exception

login()

login(\Models\str $userName, \Models\str $password)

This method is to login.

Parameters

\Models\str $userName
\Models\str $password

Throws

\Exception

redirectLogged()

redirectLogged()

This method is used when user goes to registration page.

If user is logged he is redirected to home page.

getUserName()

getUserName(int $userId) : \Models\str

By this method I get user name by user id.

Parameters

int $userId

Throws

\Exception

Returns

\Models\str

__construct()

__construct(string $host, string $username, string $password, string $db, int $port)

Parameters

string $host
string $username
string $password
string $db
int $port

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.

rawQuery()

rawQuery(string $query, array $bindParams) : 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.

array $bindParams

All variables to bind to the SQL statment.

Returns

array —

Contains the returned rows from the query.

query()

query(string $query, int $numRows) : array

Parameters

string $query

Contains a user-provided select query.

int $numRows

The number of rows total to return.

Returns

array —

Contains the returned rows from the query.

get()

get(string $tableName, integer $numRows) : 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.

getOne()

getOne(string $tableName) : array

A convenient SELECT * function to get one record.

Parameters

string $tableName

The name of the database table to work with.

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) : 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) : \MysqliDb

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.

Returns

\MysqliDb

orderBy()

orderBy( $orderByField,  $orderbyDirection) : \MysqliDb

This method allows you to specify multiple (method chaining optional) ORDER BY statements for SQL queries.

Parameters

$orderByField
$orderbyDirection

Returns

\MysqliDb

getInsertId()

getInsertId() : integer

This methods returns the ID of the last inserted item

Returns

integer —

The last inserted item ID.

escape()

escape(string $str) : string

Escape harmful characters which might affect a query.

Parameters

string $str

The string to escape.

Returns

string —

The escaped string.

__destruct()

__destruct()

Close connection

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(int $numRows, array $tableData) : \mysqli_stmt

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

It then builds the SQL query.

Parameters

int $numRows

The number of rows total to return.

array $tableData

Should contain an array of data for updating the database.

Returns

\mysqli_stmt —

Returns the $stmt object.

_dynamicBindResults()

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

Parameters

\mysqli_stmt $stmt

Equal to the prepared statement object.

Returns

array —

The results of the SQL fetch.

_prepareQuery()

_prepareQuery() : \mysqli_stmt

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

Returns

\mysqli_stmt

refValues()

refValues(array $arr) : array

Parameters

array $arr

Returns

array

_isInDb()

_isInDb( $tableName,  $columnName,  $valueToCheck)

Parameters

$tableName
$columnName
$valueToCheck