SimplePHPDB is a lightweight and easy-to-use PHP database connection and manipulation class designed for MySQL databases. It simplifies common database operations such as connecting to a database, selecting data, inserting records, updating information, and deleting data.
- Database Connection: Easily connect to a MySQL database with a few lines of code.
- CRUD Operations: Perform common database operations: Select, Insert, Update, and Delete.
- Customizable Configuration: Adjust database configuration parameters to suit your needs.
- Error Handling: Provides basic error handling and logging.
- Lightweight: A simple and compact class with minimal dependencies.
You can use this class in your PHP project to interact with a MySQL database. Here's an example of how to use it:
Before using SimplePHPDB, make sure you have the following:
- A PHP-enabled web server or environment.
- A MySQL database server.
-
Clone or download this repository to your project directory.
-
Include the
DB.php
class in your PHP script:
require 'DB.php';
// Create a new DB instance
$db = new DB();
To retrieve data from the database, use the getRows method.
// Example: Retrieve all rows from the 'users' table
$data = $db->getRows('users');
// Example: Retrieve users with a specific condition
$condition = ['where' => ['status' => 1]];
$data = $db->getRows('users', $condition);
To insert data into the database, use the insert method.
// Example: Insert a new user into the 'users' table
$data = ['username' => 'jdoe', 'email' => '[email protected]'];
$insertedId = $db->insert('users', $data);
To update data in the database, use the update method.
// Example: Update user data in the 'users' table
$data = ['email' => '[email protected]'];
$conditions = ['where' => ['username' => 'jdoe']];
$updatedRows = $db->update('users', $data, $conditions);
To delete data from the database, use the delete method.
// Example: Delete a user from the 'users' table
$conditions = ['where' => ['username' => 'jdoe']];
$deletedRows = $db->delete('users', $conditions);
Contributions are always welcome!
See contributing.md
for ways to get started.
Please adhere to this project's code of conduct
.