Database
in package
Class Database.
Table of Contents
- $config : array<string|int, mixed>
- Connection configurations.
- $debugCollector : DatabaseCollector
- $failoverIndex : int|null
- The current $config failover index to be used in a connection.
- $inTransaction : bool
- $lastQuery : string
- $logger : Logger|null
- $mysqli : mysqli|null
- __construct() : mixed
- Database constructor.
- __destruct() : mixed
- alterSchema() : AlterSchema
- Call a ALTER SCHEMA statement.
- alterTable() : AlterTable
- Call a ALTER TABLE statement.
- close() : bool
- Closes the connection if it is open.
- createSchema() : CreateSchema
- Call a CREATE SCHEMA statement.
- createTable() : CreateTable
- Call a CREATE TABLE statement.
- delete() : Delete
- Call a DELETE statement.
- dropSchema() : DropSchema
- Call a DROP SCHEMA statement.
- dropTable() : DropTable
- Call a DROP TABLE statement.
- exec() : int|string
- Executes an SQL statement and return the number of affected rows.
- getConfig() : array<string, mixed>
- getConnection() : mysqli
- Gets the MySQLi connection.
- getError() : string|null
- Get latest error.
- getErrors() : array<int, array<string, mixed>>
- Get a list of the latest errors.
- getInsertId() : int|string
- Gets the LAST_INSERT_ID().
- getLastQuery() : string
- getWarnings() : false|mysqli_warning
- getWarningsCount() : int
- insert() : Insert
- Call a INSERT statement.
- isOpen() : bool
- Tells if the connection is open.
- loadData() : LoadData
- Call a LOAD DATA statement.
- ping() : bool
- Pings the server, or tries to reconnect if the connection has gone down.
- prepare() : PreparedStatement
- Prepares a statement for execution and returns a PreparedStatement object.
- protectIdentifier() : string
- Protect identifier.
- query() : Result
- Executes an SQL statement, returning a result set as a Result object.
- quote() : float|int|string
- Quote SQL values.
- reconnect() : static
- Closes the current and opens a new connection with the last config.
- replace() : Replace
- Call a REPLACE statement.
- select() : Select
- Call a SELECT statement.
- setDebugCollector() : static
- transaction() : static
- Run statements in a transaction.
- update() : Update
- Call a UPDATE statement.
- use() : static
- with() : With
- Call a WITH statement.
- addToDebug() : mixed
- connect() : static
- finalizeAddToDebug() : void
- log() : void
- makeConfig() : array<string, mixed>
- Make Base Connection configurations.
- setCollations() : bool
- setTimezone() : bool
Properties
$config
Connection configurations.
protected
array<string|int, mixed>
$config
= []
Custom configs merged with the Base Connection configurations.
Tags
$debugCollector
protected
DatabaseCollector
$debugCollector
$failoverIndex
The current $config failover index to be used in a connection.
protected
int|null
$failoverIndex
= null
Integer representing the array index or null for none
Tags
$inTransaction
protected
bool
$inTransaction
= false
Tags
$lastQuery
protected
string
$lastQuery
= ''
$logger
protected
Logger|null
$logger
$mysqli
protected
mysqli|null
$mysqli
Methods
__construct()
Database constructor.
public
__construct(array<string, mixed>|string $username[, string|null $password = null ][, string|null $schema = null ][, string $host = 'localhost' ][, int $port = 3306 ][, Logger|null $logger = null ][, DatabaseCollector|null $collector = null ]) : mixed
Parameters
- $username : array<string, mixed>|string
- $password : string|null = null
- $schema : string|null = null
- $host : string = 'localhost'
- $port : int = 3306
- $logger : Logger|null = null
- $collector : DatabaseCollector|null = null
Tags
Return values
mixed —__destruct()
public
__destruct() : mixed
Return values
mixed —alterSchema()
Call a ALTER SCHEMA statement.
public
alterSchema([string|null $schemaName = null ]) : AlterSchema
Parameters
- $schemaName : string|null = null
Return values
AlterSchema —alterTable()
Call a ALTER TABLE statement.
public
alterTable([string|null $tableName = null ]) : AlterTable
Parameters
- $tableName : string|null = null
Return values
AlterTable —close()
Closes the connection if it is open.
public
close() : bool
Return values
bool —createSchema()
Call a CREATE SCHEMA statement.
public
createSchema([string|null $schemaName = null ]) : CreateSchema
Parameters
- $schemaName : string|null = null
Return values
CreateSchema —createTable()
Call a CREATE TABLE statement.
public
createTable([string|null $tableName = null ]) : CreateTable
Parameters
- $tableName : string|null = null
Return values
CreateTable —delete()
Call a DELETE statement.
public
delete([Closure|array<string, \Closure|string>|string|null $reference = null ], Closure|array<string, \Closure|string>|string ...$references) : Delete
Parameters
- $reference : Closure|array<string, \Closure|string>|string|null = null
- $references : Closure|array<string, \Closure|string>|string
Return values
Delete —dropSchema()
Call a DROP SCHEMA statement.
public
dropSchema([string|null $schemaName = null ]) : DropSchema
Parameters
- $schemaName : string|null = null
Return values
DropSchema —dropTable()
Call a DROP TABLE statement.
public
dropTable([string|null $table = null ], string ...$tables) : DropTable
Parameters
- $table : string|null = null
- $tables : string
Return values
DropTable —exec()
Executes an SQL statement and return the number of affected rows.
public
exec(string $statement) : int|string
Parameters
- $statement : string
Return values
int|string —getConfig()
public
getConfig() : array<string, mixed>
Return values
array<string, mixed> —getConnection()
Gets the MySQLi connection.
public
getConnection() : mysqli
Return values
mysqli —getError()
Get latest error.
public
getError() : string|null
Return values
string|null —getErrors()
Get a list of the latest errors.
public
getErrors() : array<int, array<string, mixed>>
Return values
array<int, array<string, mixed>> —getInsertId()
Gets the LAST_INSERT_ID().
public
getInsertId() : int|string
Note: When an insert has many rows, this function returns the id of the first row inserted! That is default on MySQL.
Return values
int|string —getLastQuery()
public
getLastQuery() : string
Return values
string —getWarnings()
public
getWarnings() : false|mysqli_warning
Return values
false|mysqli_warning —getWarningsCount()
public
getWarningsCount() : int
Return values
int —insert()
Call a INSERT statement.
public
insert([string|null $intoTable = null ]) : Insert
Parameters
- $intoTable : string|null = null
Return values
Insert —isOpen()
Tells if the connection is open.
public
isOpen() : bool
Return values
bool —loadData()
Call a LOAD DATA statement.
public
loadData([string|null $intoTable = null ]) : LoadData
Parameters
- $intoTable : string|null = null
Return values
LoadData —ping()
Pings the server, or tries to reconnect if the connection has gone down.
public
ping() : bool
Return values
bool —prepare()
Prepares a statement for execution and returns a PreparedStatement object.
public
prepare(string $statement) : PreparedStatement
Parameters
- $statement : string
Tags
Return values
PreparedStatement —protectIdentifier()
Protect identifier.
public
protectIdentifier(string $identifier) : string
Parameters
- $identifier : string
Tags
Return values
string —query()
Executes an SQL statement, returning a result set as a Result object.
public
query(string $statement[, bool $buffered = true ]) : Result
Must be: SELECT, SHOW, DESCRIBE or EXPLAIN
Parameters
- $statement : string
- $buffered : bool = true
Tags
Return values
Result —quote()
Quote SQL values.
public
quote(bool|float|int|string|null $value) : float|int|string
Parameters
- $value : bool|float|int|string|null
-
Value to be quoted
Tags
Return values
float|int|string —If the value is null, returns a string containing the word "NULL". If is false, "FALSE". If is true, "TRUE". If is a string, returns the quoted string. The types int or float returns the same input value.
reconnect()
Closes the current and opens a new connection with the last config.
public
reconnect() : static
Return values
static —replace()
Call a REPLACE statement.
public
replace([string|null $intoTable = null ]) : Replace
Parameters
- $intoTable : string|null = null
Return values
Replace —select()
Call a SELECT statement.
public
select([Closure|array<string, \Closure|string>|string|null $reference = null ], Closure|array<string, \Closure|string>|string ...$references) : Select
Parameters
- $reference : Closure|array<string, \Closure|string>|string|null = null
- $references : Closure|array<string, \Closure|string>|string
Return values
Select —setDebugCollector()
public
setDebugCollector(DatabaseCollector $collector) : static
Parameters
- $collector : DatabaseCollector
Return values
static —transaction()
Run statements in a transaction.
public
transaction(callable $statements) : static
Parameters
- $statements : callable
Tags
Return values
static —update()
Call a UPDATE statement.
public
update([Closure|array<string, \Closure|string>|string|null $reference = null ], Closure|array<string, \Closure|string>|string ...$references) : Update
Parameters
- $reference : Closure|array<string, \Closure|string>|string|null = null
- $references : Closure|array<string, \Closure|string>|string
Return values
Update —use()
public
use(string $schema) : static
Parameters
- $schema : string
Tags
Return values
static —with()
Call a WITH statement.
public
with() : With
Return values
With —addToDebug()
protected
addToDebug(Closure $function) : mixed
Parameters
- $function : Closure
Return values
mixed —connect()
protected
connect(array<string, mixed>|string $username[, string|null $password = null ][, string|null $schema = null ][, string $host = 'localhost' ][, int $port = 3306 ]) : static
Parameters
- $username : array<string, mixed>|string
- $password : string|null = null
- $schema : string|null = null
- $host : string = 'localhost'
- $port : int = 3306
Tags
Return values
static —finalizeAddToDebug()
protected
finalizeAddToDebug(float $start[, string|null $description = null ]) : void
Parameters
- $start : float
- $description : string|null = null
Return values
void —log()
protected
log(string $message[, LogLevel $level = LogLevel::ERROR ]) : void
Parameters
- $message : string
- $level : LogLevel = LogLevel::ERROR
Return values
void —makeConfig()
Make Base Connection configurations.
protected
makeConfig(array<string, mixed> $config) : array<string, mixed>
Parameters
- $config : array<string, mixed>
Return values
array<string, mixed> —setCollations()
protected
setCollations(string $charset, string $collation) : bool
Parameters
- $charset : string
- $collation : string
Return values
bool —setTimezone()
protected
setTimezone(string $timezone) : bool
Parameters
- $timezone : string