Crud
extends Database
in package
Database access for a table: prepare and run a query, then fetch its rows.
Table of Contents
Properties
- $db : PDO
Methods
- __construct() : mixed
- Open the shared database connection, once.
- read() : array<int, array<string, mixed>>
- Prepare and run a read query, then return its rows.
- process() : array<int, array<string, mixed>>
- Return all rows of an executed statement as associative arrays.
Properties
$db
protected
static PDO
$db
Shared PDO connection, created once on first construction.
Methods
__construct()
Open the shared database connection, once.
public
final __construct() : mixed
The first instantiation builds it from the DB_* constants and the rest
reuse it; a failure triggers E_USER_ERROR. With DEBUG on, statements
are created as DebugStatement so every query execution is timed.
Prepared statements are native, so integer columns come back as int;
the charset is utf8mb4 and the timezone is the server's.
read()
Prepare and run a read query, then return its rows.
protected
final read(string $sql[, array<int, array{0: string, 1: mixed, 2: int, 3: int}>|false $param = false ]) : array<int, array<string, mixed>>
Parameters
- $sql : string
-
SQL query with bind placeholders.
- $param : array<int, array{0: string, 1: mixed, 2: int, 3: int}>|false = false
-
Bind parameters (each: [name, value, PDO type, length]), or false for none.
Return values
array<int, array<string, mixed>> —The result rows.
process()
Return all rows of an executed statement as associative arrays.
private
process(PDOStatement $query) : array<int, array<string, mixed>>
Parameters
- $query : PDOStatement
-
Executed statement.
Return values
array<int, array<string, mixed>> —The result rows.