Magrathea PHP 2

Database extends Singleton
in package

This class will provide a layer for connecting with mysql

Table of Contents

Constants

FETCH_ARRAY  = 4
FETCH_ASSOC  = 1
FETCH_NUM  = 3
FETCH_OBJECT  = 2

Properties

$instance  : array<string|int, mixed>|null
$connDetails  : mixed
$count  : mixed
$fetchmode  : mixed
$mysqli  : mixed

Methods

__toString()  : mixed
__wakeup()  : mixed
CloseConnectionThanks()  : mixed
Already used you.. Bye.
getDatabaseName()  : string
Gets database name
ImportFile()  : mixed
imports a .sql file to the database
Instance()  : static|Singleton
Mock()  : void
MockClass()  : static|Singleton
OpenConnectionPlease()  : bool
Open connection, please. Please! 0=)
PrepareAndExecute()  : mixed
Prepares and execute a query and returns the inserted id (if any)
Query()  : object
executes the query and returns the full data
QueryAll()  : array<string|int, mixed>
executes the query and returns the full data in an array
QueryMulti()  : mixed
receives a string with multiple queries and executes them all
QueryOne()  : object
executes the query and returns only the first value of the first row of the result
QueryRow()  : array<string|int, mixed>
executes the query and returns only the first row of the result
QueryTransaction()  : mixed
receives an array of queries and executes them all
SetConnection()  : Database
Setups connection
SetConnectionArray()  : Database
Sets the connection array object
SetFetchMode()  : Database
Sets fetchmode, according with MDB2 values. Default mode: assoc.
SetInstance()  : mixed
__clone()  : mixed
__construct()  : mixed
ConnectionErrorHandle()  : MagratheaDBException
Handle connection errors @todo
ErrorHandle()  : MagratheaDBException
Handle errors @todo
FetchResult()  : mixed
Gets a mysqli result and returns an array with the rows, according to the selected fetch mode
LogControl()  : mixed
Control Log
makeValuesReferenced()  : array<string|int, mixed>
since PHP 5.3, it's necessary to pass values by reference in mysqli function to send them as args.

Constants

FETCH_ARRAY

public mixed FETCH_ARRAY = 4

FETCH_ASSOC

public mixed FETCH_ASSOC = 1

FETCH_OBJECT

public mixed FETCH_OBJECT = 2

Properties

$instance

protected static array<string|int, mixed>|null $instance = []

Methods

__toString()

public __toString() : mixed

CloseConnectionThanks()

Already used you.. Bye.

public CloseConnectionThanks() : mixed

getDatabaseName()

Gets database name

public getDatabaseName() : string
Return values
string

Database name

ImportFile()

imports a .sql file to the database

public ImportFile(string $file_path[, bool $killable = true ]) : mixed
Parameters
$file_path : string

Path of the file to import

$killable : bool = true

Should all queries be killed in case of error?

Tags
throws
MagratheaDBException

OpenConnectionPlease()

Open connection, please. Please! 0=)

public OpenConnectionPlease() : bool
Tags
throws
MagratheaDbException
Return values
bool

true or false, if connection succedded

PrepareAndExecute()

Prepares and execute a query and returns the inserted id (if any)

public PrepareAndExecute(string $query, array<string|int, mixed> $arrTypes, array<string|int, mixed> $arrValues) : mixed
@todo validates types and avoids injection. Does it?
Parameters
$query : string

Query to be executed

$arrTypes : array<string|int, mixed>

Array of types from the values to be inserted

$arrValues : array<string|int, mixed>

Array of values to be inserted

Query()

executes the query and returns the full data

public Query(string $sql) : object
Parameters
$sql : string

Query to be executed

Return values
object

$result Result of the query

QueryAll()

executes the query and returns the full data in an array

public QueryAll(string $sql) : array<string|int, mixed>
Parameters
$sql : string

Query to be executed

Return values
array<string|int, mixed>

$result Result of the query (one row for line result)

QueryMulti()

receives a string with multiple queries and executes them all

public QueryMulti(mixed $queries[, bool $killable = true ]) : mixed
Parameters
$queries : mixed
$killable : bool = true

Should all queries be killed in case of error?

Tags
todo

confirms if this is working properly

throws
MagratheaDBException

QueryOne()

executes the query and returns only the first value of the first row of the result

public QueryOne(string $sql) : object
Parameters
$sql : string

Query to be executed

Return values
object

$result First value of the first line

QueryRow()

executes the query and returns only the first row of the result

public QueryRow(array<string|int, mixed>|object|string $sql) : array<string|int, mixed>
Parameters
$sql : array<string|int, mixed>|object|string

Query to be executed

Return values
array<string|int, mixed>

$result First line of the query

QueryTransaction()

receives an array of queries and executes them all

public QueryTransaction(array<string|int, mixed> $query_array) : mixed
Parameters
$query_array : array<string|int, mixed>

Array of queries to be executed

Tags
todo

confirms if this is working properly

throws
MagratheaDBException

SetConnection()

Setups connection

public SetConnection(string $host, string $database, string $username, string $password[, mixed $port = null ]) : Database
Parameters
$host : string

host address for connection

$database : string

database name

$username : string

username for connection

$password : string

password for connection

$port : mixed = null
Return values
Database

SetConnectionArray()

Sets the connection array object

public SetConnectionArray(array<string|int, mixed> $dsn_arr) : Database
Parameters
$dsn_arr : array<string|int, mixed>

array with connection data, as the sample: array( 'hostspec' => $host, 'database' => $database, 'username' => $username, 'password' => $password, );

Return values
Database

SetFetchMode()

Sets fetchmode, according with MDB2 values. Default mode: assoc.

public SetFetchMode(string $fetch) : Database
Parameters
$fetch : string

fetchmode for SQL returns options available: assoc: array with keys as the column names object: object with columns as properties if anything different from those values is sent, "assoc" is used

Return values
Database

SetInstance()

public SetInstance(mixed $inst) : mixed
Parameters
$inst : mixed

__construct()

private final __construct() : mixed

ConnectionErrorHandle()

Handle connection errors @todo

private ConnectionErrorHandle([mixed $msg = "" ][, mixed $data = null ]) : MagratheaDBException
Parameters
$msg : mixed = ""
$data : mixed = null
Tags
throws
MagratheaDbException
Return values
MagratheaDBException

ErrorHandle()

Handle errors @todo

private ErrorHandle(mixed $error, mixed $sql[, mixed $values = null ]) : MagratheaDBException
Parameters
$error : mixed
$sql : mixed
$values : mixed = null
Tags
throws
MagratheaDbException
Return values
MagratheaDBException

FetchResult()

Gets a mysqli result and returns an array with the rows, according to the selected fetch mode

private FetchResult(object $result[, bool $firstLineOnly = false ]) : mixed
Parameters
$result : object

result to be fetched

$firstLineOnly : bool = false

should we fetch all the result or do we need only the first line?

LogControl()

Control Log

private LogControl(string $sql[, object|array<string|int, mixed> $values = null ]) : mixed
Parameters
$sql : string

Query to be logged

$values : object|array<string|int, mixed> = null

Values to be logged

makeValuesReferenced()

since PHP 5.3, it's necessary to pass values by reference in mysqli function to send them as args.

private makeValuesReferenced(array<string|int, mixed> $arr) : array<string|int, mixed>

Details can be found on @link http://php.net/manual/en/mysqli-stmt.bind-param.php

Parameters
$arr : array<string|int, mixed>

array to be "converted"

Return values
array<string|int, mixed>

array as reference, ready to be used!


        
On this page

Search results