The PostgresqlDriver.php file in the PHPFast framework defines a class for seamless interaction with a PostgreSQL database using PDO (PHP Data Objects). This class offers essential methods for establishing connections, executing queries, and handling data efficiently. Below is a comprehensive breakdown of each method, along with practical usage examples.
Initializes the PostgreSQL connection using the provided configuration settings.
$config: An array containing the database configuration settings.
query()
Executes an arbitrary SQL query with optional parameters.
$query: The SQL query string.
$params: An array of values corresponding to the parameters in the SQL query.
return: Result of the query (used for SELECT, INSERT, UPDATE, DELETE).
lastInsertId()
Retrieves the ID of the last inserted record.
return: ID of the last inserted record.
count()
Counts the number of records in a table that match the specified filter criteria
$table: The name of the table.
$where: The filter criteria (optional).
$params: An array of values corresponding to the parameters in the filter criteria (optional).
return: Number of records in the table.
fetchAll()
Executes a SELECT query on a table and retrieves multiple rows that match the specified filter criteria.
$table: The name of the table.
$where: The filter criteria (optional).
$params: An array of values corresponding to the parameters in the filter criteria (optional).
$orderBy: The ORDER BY clause (optional).
$page: The current page number (optional).
$limit: The number of results per page (optional).
return: Array containing the query results.
fetchPagination()
Executes a SELECT query on a table and retrieves multiple rows with pagination support.
$table: The name of the table.
$where: The filter criteria (optional).
$params: An array of values corresponding to the parameters in the filter criteria (optional).
$orderBy: The ORDER BY clause (optional).
$page: The current page number (optional).
$limit: The number of results per page (optional).
return: Query results and information about whether there is a next page.
fetchRow()
Executes a SELECT query on a table and retrieves a single row that matches the specified filter criteria.
$table: The name of the table.
$where: The filter criteria (optional).
$params: An array of values corresponding to the parameters in the filter criteria (optional).
$orderBy: The ORDER BY clause (optional).
$page: The current page number (optional).
return: Array containing the query result or null if no result is found.
insert()
Inserts a new row into a table with the specified data.
$table: The name of the table.
$data: An array of data to insert (in the form of 'column' => 'value').
return: Returns true if the data is successfully inserted, otherwise false
update()
Updates rows in a table that match the specified filter criteria with the provided data.
$table: The name of the table.
$data: An array of data to update (in the form of 'column' => 'value').
$where: The filter criteria (optional).
$params: An array of values corresponding to the parameters in the filter criteria (optional).
return: Returns true if the update is successful, otherwise false.
delete()
Deletes rows from a table that match the specified filter criteria.
$table: The name of the table.
$where: The filter criteria (optional).
$params: An array of values corresponding to the parameters in the filter criteria (optional).
return: Returns true if the deletion is successful, otherwise false
Summary
he PostgresqlDriver.php file offers a robust collection of methods for seamless interaction with a PostgreSQL database using PDO. It facilitates essential operations such as querying, inserting, updating, and deleting records, along with transaction management and pagination support. Designed for efficiency, this implementation enables developers to handle database operations smoothly within their PHPFast applications.