Database

The Database.php file in the Drivers/Database/ directory of the PHPFast framework provides methods to interact with the database. Each specific database driver (e.g., MySQL, PostgreSQL) will implement these methods. Below is a detailed explanation of each method along.

PHPFast is a lightweight and efficient PHP framework designed to streamline web application development while providing flexibility and scalability. One of its key features is the built-in support for multiple database drivers, making it easy to integrate and work with different database systems. PHPFast includes drivers for MongoDB, MySQL, and PostgreSQL, allowing developers to choose the best database solution for their application needs.

  • MongodbDriver: For applications that require NoSQL databases, PHPFast offers seamless integration with MongoDB, a high-performance, flexible database ideal for handling unstructured data.

  • MysqlDriver: PHPFast supports MySQL, one of the most widely used relational databases, providing robust and efficient data management for traditional applications.

  • PostgresqlDriver: With built-in support for PostgreSQL, PHPFast enables the use of an advanced, open-source relational database known for its reliability, performance, and scalability.

Constructor (__construct)

abstract public function __construct($config);

Initializes the database connection with the provided configuration.\

  • $config: An array containing the database configuration settings.

query()

abstract public function query($query, $params = []);

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.

lastInsertId()

abstract public function lastInsertId();

Retrieves the ID of the last inserted record.

The ID of the last inserted record.

count()

abstract public function count($table, $where = '', $params = []);

Counts the number of records in a table.

  • $table: The name of the table.

  • $where: The WHERE clause to filter records (optional).

  • $params: An array of values corresponding to the parameters in the WHERE clause (optional).

fetchAll()

abstract public function fetchAll($table, $where = '', $params = [], $orderBy = '', $page = 1, $limit = null);

Executes a SELECT query to retrieve multiple rows.

  • $table: The name of the table.

  • $where: The WHERE clause as a string (optional).

  • $params: An array of values corresponding to the parameters in the WHERE clause (optional).

  • $orderBy: The ORDER BY clause (optional).

  • $page: The current page number (optional).

  • $limit: The number of results to limit (optional).

fetchPagination()

abstract public function fetchPagination($table, $where = '', $params = [], $orderBy = '', $page = 1, $limit = null);

Executes a SELECT query to retrieve multiple rows with pagination support.

  • $table: The name of the table.

  • $where: The WHERE clause as a string (optional).

  • $params: An array of values corresponding to the parameters in the WHERE clause (optional).

  • $orderBy: The ORDER BY clause (optional).

  • $page: The current page number (optional).

  • $limit: The number of results per page (optional).

fetchRow()

abstract public function fetchRow($table, $where = '', $params = [], $orderBy = '', $page = 1);

Executes a SELECT query to retrieve a single row.

  • $table: The name of the table.

  • $where: The WHERE clause as a string.

  • $params: An array of values corresponding to the parameters in the WHERE clause.

  • $orderBy: The ORDER BY clause (optional).

  • $page: The current page number (optional).

insert()

abstract public function insert($table, $data);

Executes an INSERT query to add a new record.

  • $table: The name of the table.

  • $data: An array of data to insert (in the form of 'column' => 'value').

update()

abstract public function update($table, $data, $where = '', $params = []);

Executes an UPDATE query to modify existing records.

  • $table: The name of the table.

  • $data: An array of data to update (in the form of 'column' => 'value').

  • $where: The WHERE clause to filter records.

  • $params: An array of values corresponding to the parameters in the WHERE clause.

delete()

abstract public function delete($table, $where = '', $params = []);

Executes a DELETE query to remove records.

  • $table: The name of the table.

  • $where: The WHERE clause to filter records.

  • $params: An array of values corresponding to the parameters in the WHERE clause.

Last updated

Was this helpful?