Documentation

MySQL
in package

Weaver Framework - MySQL Database Connection Class

This class provides a MySQL database connection and common database operations. It implements the Singleton pattern to ensure a single database connection is used.

Table of Contents

Properties

$conn  : mixed
$database  : mixed
$host  : mixed
$instance  : mixed
$password  : mixed
$username  : mixed

Methods

affectedRows()  : int
Get the number of affected rows by the last INSERT, UPDATE, DELETE query.
escape()  : string
Escape a string for safe use in SQL queries.
getInstance()  : MySQL
Get the Singleton instance of the MySQL class.
insertID()  : int
Get the last inserted ID from an auto-increment field.
lockTable()  : mixed
Lock a database table for write operations.
lockTables()  : mixed
Lock multiple database tables for write operations.
query()  : mixed
Execute a database query.
result()  : array<string|int, mixed>
Retrieve query results as an array of objects.
unlockTables()  : mixed
Unlock previously locked database tables.
__construct()  : mixed
connect()  : mixed
Establish a database connection.

Properties

$database

private mixed $database

$instance

private static mixed $instance

$password

private mixed $password

$username

private mixed $username

Methods

affectedRows()

Get the number of affected rows by the last INSERT, UPDATE, DELETE query.

public affectedRows() : int
Return values
int

The number of affected rows, or -1 if no query has been executed.

escape()

Escape a string for safe use in SQL queries.

public escape(string $string) : string
Parameters
$string : string

The string to escape.

Return values
string

The escaped string.

getInstance()

Get the Singleton instance of the MySQL class.

public static getInstance() : MySQL
Return values
MySQL

The MySQL instance.

insertID()

Get the last inserted ID from an auto-increment field.

public insertID() : int
Return values
int

The last inserted ID.

lockTable()

Lock a database table for write operations.

public lockTable(string $table) : mixed
Parameters
$table : string

The name of the table to lock.

lockTables()

Lock multiple database tables for write operations.

public lockTables(array<string|int, mixed> $tables) : mixed
Parameters
$tables : array<string|int, mixed>

An array of table names to lock.

query()

Execute a database query.

public query(string $sql) : mixed
Parameters
$sql : string

The SQL query to execute.

Return values
mixed

The query result or false on error.

result()

Retrieve query results as an array of objects.

public result(mysqli_result $result) : array<string|int, mixed>
Parameters
$result : mysqli_result

The query result.

Return values
array<string|int, mixed>

An array of objects representing query results.

unlockTables()

Unlock previously locked database tables.

public unlockTables() : mixed

__construct()

private __construct(mixed $host, mixed $username, mixed $password, mixed $database) : mixed
Parameters
$host : mixed
$username : mixed
$password : mixed
$database : mixed

connect()

Establish a database connection.

private connect() : mixed

        
On this page

Search results