PdoDriver
in package
implements
DatabaseDriver
Class PdoDriver
This class implements the DatabaseDriver interface and provides functionality for interacting with a database using PHP's PDO (PHP Data Objects).
Table of Contents
Interfaces
- DatabaseDriver
- Interface DatabaseDriver
Properties
- $pdo : PDO|null
- $tableToQuery : string
Methods
- close() : void
- Closes the connection to the database.
- connect() : void
- Establishes a connection to the database.
- delete() : void
- Deletes a record from the database based on the provided data.
- get() : array<string|int, mixed>
- Retrieves data from the database based on the provided criteria.
- insert() : void
- Inserts a new record into the database.
- lastInsertId() : int|false
- Retrieves the ID of the last inserted row.
- statement() : mixed
- Prepares and executes a database statement.
- table() : static
- Sets the table name for the database query.
Properties
$pdo
protected
PDO|null
$pdo
$tableToQuery
private
string
$tableToQuery
Methods
close()
Closes the connection to the database.
public
close() : void
Tags
connect()
Establishes a connection to the database.
public
connect(string $protocol, string $host, int $port, string $user, string $password, string $database) : void
Parameters
- $protocol : string
-
The protocol to use for the connection (e.g., 'mysql', 'pgsql').
- $host : string
-
The hostname or IP address of the database server.
- $port : int
-
The port number to connect to on the database server.
- $user : string
-
The username for authentication.
- $password : string
-
The password for authentication.
- $database : string
-
The name of the database to connect to.
Tags
delete()
Deletes a record from the database based on the provided data.
public
delete(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
-
An associative array containing the criteria for deletion.
Tags
get()
Retrieves data from the database based on the provided criteria.
public
get([array<string|int, mixed>|null $data = null ]) : array<string|int, mixed>
Parameters
- $data : array<string|int, mixed>|null = null
-
Optional associative array of criteria to filter the data. If null, retrieves all data.
Tags
Return values
array<string|int, mixed> —An array of results matching the criteria.
insert()
Inserts a new record into the database.
public
insert(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
-
An associative array containing the data to be inserted, where the keys represent column names and the values represent the corresponding values to be stored.
Tags
lastInsertId()
Retrieves the ID of the last inserted row.
public
lastInsertId() : int|false
Tags
Return values
int|false —The ID of the last inserted row in the database or false on failure.
statement()
Prepares and executes a database statement.
public
statement(string $query[, array<string|int, mixed> $bind = [] ]) : mixed
Parameters
- $query : string
-
The SQL query to execute.
- $bind : array<string|int, mixed> = []
-
An optional associative array of parameters to bind to the query.
Tags
Return values
mixed —The result of the query execution, format depends on the implementation.
table()
Sets the table name for the database query.
public
table(string $table) : static
Parameters
- $table : string
-
The name of the table to interact with.
Return values
static —Returns the current instance for method chaining.