An open API service indexing awesome lists of open source software.

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.

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.

![tag](https://img.shields.io/badge/tag-PHP%20Library-bb4444)
![size](https://img.shields.io/github/size/pardnchiu/PHP-SQL/src/SQL.php)

![version](https://img.shields.io/packagist/v/pardnchiu/sql)
![download](https://img.shields.io/packagist/dm/pardnchiu/sql)

## 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)