Database
class Database
Database interface class
Methods
Create a new connection to the database
Destroy this connection to the database
Get an instance of the Database object
Close the current connection to the MySQL database
Tests whether or not the connection to the database is still active
Get the unique row ID of the last row that was inserted
Prepares and executes a MySQL prepared INSERT/DELETE/UPDATE statement. The second parameter is optional when using this function to execute a query with no placeholders.
Prepares and executes a MySQL prepared SELECT statement. The second parameter is optional when using this function to execute a query with no placeholders.
Start a MySQL transaction
Commit the stored queries (usable only if a transaction has been started)
Cancel all pending queries (does not finish the transaction
Commit all pending queries and finalise the transaction
Serialize the object
Details
at line line 51
__construct(string $host, string $user, string $password, string $dbName)
Create a new connection to the database
at line line 85
__destruct()
Destroy this connection to the database
at line line 99
static Database
getInstance()
Get an instance of the Database object
This should be the main way to acquire access to the database
at line line 129
closeConnection()
Close the current connection to the MySQL database
at line line 139
bool
isConnected()
Tests whether or not the connection to the database is still active
at line line 148
int
getInsertId()
Get the unique row ID of the last row that was inserted
at line line 160
int
execute(string $queryText, mixed|array $params = false)
Prepares and executes a MySQL prepared INSERT/DELETE/UPDATE statement. The second parameter is optional when using this function to execute a query with no placeholders.
at line line 183
array
query(string $queryText, mixed|array $params = false)
Prepares and executes a MySQL prepared SELECT statement. The second parameter is optional when using this function to execute a query with no placeholders.
at line line 252
startTransaction()
Start a MySQL transaction
at line line 262
commit()
Commit the stored queries (usable only if a transaction has been started)
This does not show an error if there are no queries to commit
at line line 270
rollback()
Cancel all pending queries (does not finish the transaction
at line line 278
finishTransaction()
Commit all pending queries and finalise the transaction
at line line 292
error(string $error, int $id = null, Throwable $previous = null)
Uses monolog to log an error message
at line line 315
array
__sleep()
Serialize the object
Prevents PDO from being erroneously serialized