progrmanial / fast-sql
A secure and flexible PHP class for generating SQL queries.
dev-main
2025-01-05 05:34 UTC
Requires
- php: >=7.2
- ext-pdo: *
This package is auto-updated.
Last update: 2025-04-05 06:08:15 UTC
README
fast-sql is a PHP class designed to provide a secure and flexible way to generate SQL queries. It supports various SQL operations, parameter binding to prevent SQL injection, transactions, and caching for improved performance.
Installation
You can install fast-sql using Composer. Add the following to your composer.json
file:
{ "require": { "progrmanial/fast-sql": "dev-master" } }
Then run:
composer install
Usage
<?php use progrmanial\FASTSQL\SecureSQLGenerator; use PDO; // Create a PDO instance for mysql database connection $pdo = new PDO('mysql:host=localhost;dbname=your_database', 'username', 'password'); // Create an instance of SecureSQLGenerator $sqlGenerator = new SecureSQLGenerator($pdo); // Example: SELECT operation $result = $sqlGenerator ->select(['id', 'name']) ->from('users') ->where(['status' => 'active']) ->execute(); // Example: INSERT operation $sqlGenerator ->insert('products', ['name' => 'Product A', 'price' => 29.99]) ->execute(); // Example: JOIN operation $result = $sqlGenerator ->select(['users.id', 'users.name', 'orders.total']) ->from('users') ->innerJoin('orders', ['users.id' => 'orders.user_id']) ->execute();
Features
- Secure: Uses parameter binding to prevent SQL injection.
- Flexible: Supports various SQL operations, including SELECT, INSERT, UPDATE, DELETE, and JOIN.
- Transaction Management: Provides methods for starting, committing, and rolling back transactions.
- Caching: Optionally caches query results for improved performance.
- Set Operations: Supports INTERSECT, UNION, and EXCEPT set operations.
Contributing
If you find any issues or have suggestions for improvements, feel free to open an issue or submit a pull request.
License
This project is licensed under the MIT License - see the LICENSE file for details.