PHP Database

PostgreSql extends AbstractDatabase
in package

Simple PostgreSQL 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()  : PostgreSqlDTO
Retrieve postgresql database.
functionsFactory()  : array<string|int, string>
Retrieve postgresql 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::INTEGER => ["int2", "int4", "int8", "bool"], \Samy\Database\Constant\DatabaseFieldType::FLOAT => ["numeric", "float4", "float8", "money"], \Samy\Database\Constant\DatabaseFieldType::STRING => ["bpchar", "varchar", "text", "tsquery", "tsvector", "uuid", "xml", "json", "jsonb", "name"], \Samy\Database\Constant\DatabaseFieldType::TIME => ["date", "time", "timestamp", "timestamptz", "interval"]]

$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 postgresql database.

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

The data configuration.

Tags
throws
DatabaseException

If error.

throws
ValidationException

If invalid.

Return values
PostgreSqlDTO

functionsFactory()

Retrieve postgresql 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(PostgreSqlResultDTO $ResultSet) : array<string, int>
Parameters
$ResultSet : PostgreSqlResultDTO

The query result set

Return values
array<string, int>

        
On this page

Search results