PHP Database

MySql extends AbstractDatabase
in package

Simple MySQL implementation.

Table of Contents

Properties

$affected_rows  : int
$database  : MySqlDTO|PostgreSqlDTO|mixed
$executed  : string
$field_types  : mixed
$functions  : array<string|int, string>
$insert_id  : int
$queried  : string

Methods

__construct()  : mixed
count()  : int
Retrieve total existing record.
delete()  : static
Return an instance with deleted record.
escape()  : string
Escapes special characters in a string for use in an SQL statement.
execute()  : static
Return an instance with executed query command.
getAffectedRows()  : int
Retrieve number of affected rows in the last execute() operation.
getExecuted()  : string
Retrieve the last command that was run in execute() operation.
getInsertId()  : int
Retrieve the ID generated in the last execute() operation.
getQueried()  : string
Retrieve the last command that was run in query() operation.
insert()  : static
Return an instance with inserted new record.
isFunction()  : bool
Check if data expression is sql function.
query()  : array<string|int, array<string, mixed>>
Retrieve records from query command.
record()  : array<string, mixed>
Retrieve single row record from query command.
select()  : array<string|int, array<string, mixed>>
Retrieve multiple row records from query command.
update()  : static
Return an instance with updated record.
databaseFactory()  : MySqlDTO
Retrieve mysql database.
functionsFactory()  : array<string|int, string>
Retrieve mysql functions.
getFieldOperant()  : string
Retrieve field value.
getFieldType()  : int
Retrieve field type.
getFieldValue()  : string
Retrieve field value.
getIdentifier()  : string
Retrieve identifier name.
getResultValue()  : mixed
Retrieve query result value.
getSqlField()  : string
Retrieve SQL field statement.
getSqlFilter()  : string
Retrieve SQL filter statement.
getSqlGroup()  : string
Retrieve SQL group statement.
getSqlInsert()  : array<string, string>
Retrieve SQL insert statements.
getSqlOrder()  : string
Retrieve SQL order statement.
getSqlSet()  : string
Retrieve SQL data statement.
getSqlTable()  : string
Retrieve SQL table statement.
getResultTypes()  : array<string, int>
Retrieve query result types.

Properties

$database

protected MySqlDTO|PostgreSqlDTO|mixed $database = null

$field_types

protected mixed $field_types = [\Samy\Database\Constant\DatabaseFieldType::NULL => [MYSQLI_TYPE_NULL], \Samy\Database\Constant\DatabaseFieldType::OBJECT => [MYSQLI_TYPE_JSON, MYSQLI_TYPE_ENUM, MYSQLI_TYPE_INTERVAL, MYSQLI_TYPE_SET, MYSQLI_TYPE_GEOMETRY], \Samy\Database\Constant\DatabaseFieldType::BOOLEAN => [MYSQLI_TYPE_BIT], \Samy\Database\Constant\DatabaseFieldType::INTEGER => [MYSQLI_TYPE_TINY, MYSQLI_TYPE_CHAR, MYSQLI_TYPE_SHORT, MYSQLI_TYPE_LONG, MYSQLI_TYPE_LONGLONG, MYSQLI_TYPE_INT24], \Samy\Database\Constant\DatabaseFieldType::FLOAT => [MYSQLI_TYPE_DECIMAL, MYSQLI_TYPE_FLOAT, MYSQLI_TYPE_DOUBLE, MYSQLI_TYPE_NEWDECIMAL], \Samy\Database\Constant\DatabaseFieldType::STRING => [MYSQLI_TYPE_TINY_BLOB, MYSQLI_TYPE_MEDIUM_BLOB, MYSQLI_TYPE_LONG_BLOB, MYSQLI_TYPE_BLOB, MYSQLI_TYPE_VAR_STRING, MYSQLI_TYPE_STRING], \Samy\Database\Constant\DatabaseFieldType::TIME => [MYSQLI_TYPE_TIMESTAMP, MYSQLI_TYPE_DATE, MYSQLI_TYPE_TIME, MYSQLI_TYPE_DATETIME, MYSQLI_TYPE_YEAR, MYSQLI_TYPE_NEWDATE]]

$functions

protected array<string|int, string> $functions = []

Methods

__construct()

public __construct([array<string, mixed> $Config = [] ]) : mixed
Parameters
$Config : array<string, mixed> = []

The database configuration.

Tags
throws
DatabaseException

If error.

throws
ValidationException

If invalid.

count()

Retrieve total existing record.

public count(array<string, mixed> $Data) : int
Parameters
$Data : array<string, mixed>

The count data.

Tags
throws
DatabaseException

If error.

throws
ValidationException

If invalid.

Return values
int

delete()

Return an instance with deleted record.

public delete(array<string, mixed> $Data) : static
Parameters
$Data : array<string, mixed>

The delete data.

Tags
throws
DatabaseException

If error.

throws
ValidationException

If invalid.

Return values
static

escape()

Escapes special characters in a string for use in an SQL statement.

public escape(string $UnescapedString) : string

Escapes special characters in the unescaped_string, taking into account the current character set of the connection so that it is safe to place it in a execute() or query(). If binary data is to be inserted, this function must be used.

This function must always (with few exceptions) be used to make data safe before sending a query.

Parameters
$UnescapedString : string

The unescaped string.

Return values
string

execute()

Return an instance with executed query command.

public execute(string $Command) : static
Parameters
$Command : string

The sql command.

Tags
throws
DatabaseException

If error.

Return values
static

getAffectedRows()

Retrieve number of affected rows in the last execute() operation.

public getAffectedRows() : int
Return values
int

getExecuted()

Retrieve the last command that was run in execute() operation.

public getExecuted() : string
Return values
string

getInsertId()

Retrieve the ID generated in the last execute() operation.

public getInsertId() : int
Return values
int

getQueried()

Retrieve the last command that was run in query() operation.

public getQueried() : string
Return values
string

insert()

Return an instance with inserted new record.

public insert(array<string, mixed> $Data) : static
Parameters
$Data : array<string, mixed>

The create data.

Tags
throws
DatabaseException

If error.

throws
ValidationException

If invalid.

Return values
static

isFunction()

Check if data expression is sql function.

public isFunction(string $Expression) : bool
Parameters
$Expression : string

The sql expression.

Return values
bool

query()

Retrieve records from query command.

public query(string $Command) : array<string|int, array<string, mixed>>
Parameters
$Command : string

The sql command.

Tags
throws
DatabaseException

If error.

Return values
array<string|int, array<string, mixed>>

record()

Retrieve single row record from query command.

public record(array<string, mixed> $Read) : array<string, mixed>
Parameters
$Read : array<string, mixed>

The read data.

Tags
throws
DatabaseException

If error.

throws
ValidationException

If invalid.

Return values
array<string, mixed>

select()

Retrieve multiple row records from query command.

public select(array<string, mixed> $Data) : array<string|int, array<string, mixed>>
Parameters
$Data : array<string, mixed>

The read data.

Tags
throws
DatabaseException

If error.

throws
ValidationException

If invalid.

Return values
array<string|int, array<string, mixed>>

update()

Return an instance with updated record.

public update(array<string, mixed> $Data) : static
Parameters
$Data : array<string, mixed>

The update data.

Tags
throws
DatabaseException

If error.

throws
ValidationException

If invalid.

Return values
static

databaseFactory()

Retrieve mysql database.

protected databaseFactory(array<string, mixed> $Data) : MySqlDTO
Parameters
$Data : array<string, mixed>

The data configuration.

Tags
throws
DatabaseException

If error.

throws
ValidationException

If invalid.

Return values
MySqlDTO

functionsFactory()

Retrieve mysql functions.

protected functionsFactory() : array<string|int, string>
Tags
throws
DatabaseException

If error.

throws
ValidationException

If invalid.

Return values
array<string|int, string>

getFieldOperant()

Retrieve field value.

protected getFieldOperant(mixed $Value, bool $UseSensitiveCase) : string
Parameters
$Value : mixed

The value

$UseSensitiveCase : bool

Use sensitive-case operator.

Return values
string

getFieldType()

Retrieve field type.

protected getFieldType(mixed $Type) : int
Parameters
$Type : mixed

The database type

Return values
int

getFieldValue()

Retrieve field value.

protected getFieldValue(mixed $Value) : string
Parameters
$Value : mixed

The value

Return values
string

getIdentifier()

Retrieve identifier name.

protected getIdentifier(string $UnidentifiedName) : string
Parameters
$UnidentifiedName : string

The unidentified name.

Return values
string

getResultValue()

Retrieve query result value.

protected getResultValue(array<string, int> $Types, string $Name, mixed $Value) : mixed
Parameters
$Types : array<string, int>

Result types

$Name : string

Field name

$Value : mixed

Field value

getSqlField()

Retrieve SQL field statement.

protected getSqlField(array<int|string, string> $Field) : string
Parameters
$Field : array<int|string, string>

The field data.

Return values
string

getSqlFilter()

Retrieve SQL filter statement.

protected getSqlFilter(array<string|int, mixed> $Filter, bool $UseSensitiveCase[, bool $UseOrCondition = false ]) : string
Parameters
$Filter : array<string|int, mixed>

The filter data.

$UseSensitiveCase : bool

Use sensitive-case operator.

$UseOrCondition : bool = false

Use OR condition.

Return values
string

getSqlGroup()

Retrieve SQL group statement.

protected getSqlGroup(array<string|int, string> $Group) : string
Parameters
$Group : array<string|int, string>

The group data.

Return values
string

getSqlInsert()

Retrieve SQL insert statements.

protected getSqlInsert(array<string, mixed> $Data) : array<string, string>
Parameters
$Data : array<string, mixed>

The data.

Return values
array<string, string>

getSqlOrder()

Retrieve SQL order statement.

protected getSqlOrder(array<string, string> $Order) : string
Parameters
$Order : array<string, string>

The order data.

Return values
string

getSqlSet()

Retrieve SQL data statement.

protected getSqlSet(array<string, mixed> $Data) : string
Parameters
$Data : array<string, mixed>

The set data.

Return values
string

getSqlTable()

Retrieve SQL table statement.

protected getSqlTable(string|array<string|int, string> $Table) : string
Parameters
$Table : string|array<string|int, string>

The table data.

Return values
string

getResultTypes()

Retrieve query result types.

private getResultTypes(mysqli_result $ResultSet) : array<string, int>
Parameters
$ResultSet : mysqli_result

The query result set

Return values
array<string, int>

        
On this page

Search results