https://github.com/pardnchiu/php-sql
PD\SQL is a PDO-based SQL query builder that provides an elegant and secure way to construct and execute database queries in PHP.
https://github.com/pardnchiu/php-sql
mariadb mysql pardnchiu pardnio pardnltd pdo php-composer php-library
Last synced: 8 days ago
JSON representation
PD\SQL is a PDO-based SQL query builder that provides an elegant and secure way to construct and execute database queries in PHP.
- Host: GitHub
- URL: https://github.com/pardnchiu/php-sql
- Owner: pardnchiu
- License: mit
- Created: 2025-02-02T20:12:35.000Z (3 months ago)
- Default Branch: master
- Last Pushed: 2025-02-03T12:33:04.000Z (3 months ago)
- Last Synced: 2025-03-03T16:51:31.281Z (about 2 months ago)
- Topics: mariadb, mysql, pardnchiu, pardnio, pardnltd, pdo, php-composer, php-library
- Language: PHP
- Homepage:
- Size: 8.79 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PD\SQL
> PD\SQL is a PDO-based SQL query builder that provides an elegant and secure way to construct and execute database queries in PHP.



## Features
- Fluent interface for building SQL queries
- Safe parameter binding to prevent SQL injection
- Support for complex JOIN operations (INNER, LEFT, RIGHT)
- Dynamic WHERE clause construction
- Ordering and pagination support
- Transaction handling
- Query execution time monitoring
- Environment-based configuration
- Automatic connection management## functions
- Table selection with `table()`
- Custom field selection with `select()`
- Conditional filtering with `where()`
- Join operations with `join()`, `left_join()`, `right_join()`
- Result ordering with `order_by()`
- Pagination with `limit()` and `offset()`
- Record creation with `insertGetId()`
- Record updates with `update()`
- Total row count with `total()`
- Raw query execution with `query()` for complex custom queries## How to Use
### Install
```shell
composer require pardnchiu/sql
``````php
where("status", "active")
->where("age", ">", 18)
->get();$result_order = SQL::table("orders")
->select("orders.*", "users.name")
->join("users", "orders.user_id", "users.id")
->where("orders.status", "pending")
->get();$result_product = SQL::table("products")
->total()
->limit(10)
->offset(0)
->order_by("created_at", "DESC")
->get();$result_user_1 = SQL::query(
"SELECT * FROM users WHERE status = ? AND role = ?",
["active", "admin"]
);try {
$result = SQL::table("users")
->where("id", 1)
->update([
"status" => "active",
"updated_at" => "NOW()"
]);if (!empty($result["info"])) {
echo "Performance: " . $result["info"];
};
} catch (\PDOException $e) {
echo "Database Error: " . $e->getMessage();
} catch (\Exception $e) {
echo "General Error: " . $e->getMessage();
};
```## License
This source code project is licensed under the [MIT](https://github.com/pardnchiu/PHP-SQL/blob/main/LICENSE) license.
## Creator
邱敬幃 Pardn Chiu
***
©️ 2024 [邱敬幃 Pardn Chiu](https://pardn.io)