Magrathea PHP 2

DatabaseSimulate extends Singleton
in package

This class will provide a simulation of MagratheaDatabase queries will be saved on a file.

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

Methods

__wakeup()  : mixed
CloseConnectionThanks()  : mixed
Already used you.. Bye.
Instance()  : static|Singleton
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|null
executes the query and returns the full data
QueryAll()  : array<string|int, mixed>
executes the query and returns the full data in an array
QueryOne()  : object|null
executes the query and returns only the first value of the first row of the result
QueryRow()  : object|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()  : DatabaseSimulate
Setups connection
SetConnectionArray()  : DatabaseSimulate
Sets the connection array object
SetFetchMode()  : DatabaseSimulate
Sets fetchmode, according with MDB2 values. Default mode: assoc.
SetInstance()  : mixed
__clone()  : mixed
__construct()  : mixed
ConnectionErrorHandle()  : mixed
Handle connection errors @todo
ErrorHandle()  : mixed
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.
Simulate()  : string
Just fake it!

Constants

Properties

$instance

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

Methods

CloseConnectionThanks()

Already used you.. Bye.

public CloseConnectionThanks() : mixed

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|null
Parameters
$sql : string

Query to be executed

Return values
object|null

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

QueryOne()

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

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

Query to be executed

Return values
object|null

$result First value of the first line

QueryRow()

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

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

Query to be executed

Return values
object|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 ]) : DatabaseSimulate
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
DatabaseSimulate

SetConnectionArray()

Sets the connection array object

public SetConnectionArray(array<string|int, mixed> $dsn_arr) : DatabaseSimulate
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
DatabaseSimulate

SetFetchMode()

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

public SetFetchMode(string $fetch) : DatabaseSimulate
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
DatabaseSimulate

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 ]) : mixed
Parameters
$msg : mixed = ""
$data : mixed = null
Tags
throws
MagratheaDbException

ErrorHandle()

Handle errors @todo

private ErrorHandle(mixed $error, mixed $sql[, mixed $values = null ]) : mixed
Parameters
$error : mixed
$sql : mixed
$values : mixed = null
Tags
throws
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[, array<string|int, mixed> $values = null ]) : mixed
Parameters
$sql : string

Query to be logged

$values : 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!

Simulate()

Just fake it!

private Simulate(mixed $fn, mixed $sql[, mixed $values = null ]) : string
Parameters
$fn : mixed
$sql : mixed
$values : mixed = null
Return values
string

simulation


        
On this page

Search results