A lightweight and simple PHP class for managing database connections and queries using PDO.
- Easy-to-use PDO-based database connection.
- Support for basic CRUD operations (Create, Read, Update, Delete).
- Secure and configurable for different database types.
- PHP 7.4 or higher
- PDO extension enabled
- A supported database (e.g., MySQL, PostgreSQL)
- Clone the repository:
git clone https://github.com/mohamad-slime/simple-database-php-class.git
- Navigate to the project directory:
cd simple-database-php-class - Install dependencies using Composer:
composer install
- Configure your database connection in a
.envfile (see Environment Variables).
require 'vendor/autoload.php';
use SimpleDatabase\Database;
try {
$db = new Database('mysql', 'localhost', 'mydb', 'username', 'password');
$results = $db->select('users', ['id', 'name'], ['age' => 25]);
print_r($results);
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}- Create a
.envfile in the project root with your database credentials (see.env.example). - Run the example:
php examples/example.php
Create a .env file in the project root and add your database credentials:
DB_HOST=localhost
DB_NAME=mydb
DB_USER=username
DB_PASS=password
DB_TYPE=mysql
Run unit tests using PHPUnit:
vendor/bin/phpunit tests- Fork the repository.
- Create a new branch (
git checkout -b feature-branch). - Make your changes and commit (
git commit -m 'Add new feature'). - Push to the branch (
git push origin feature-branch). - Create a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.