Download the PHP package sentgine/db without Composer
On this page you can find all versions of the php package sentgine/db. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package db
Short Description A lightweight PHP PDO-based query builder for simplified database interactions.
License MIT
Informations about the package db
DB by Sentgine
A standalone database query builder wrapper using PDO.
Features
Database Connection:
- Establishes a database connection using PDO (PHP Data Objects) to interact with MySQL databases.
- Supports multiple database drivers including MySQL, PostgreSQL, and SQLite.
- Handles database connection errors and exceptions gracefully.
Query Building:
- Provides fluent interface methods for building SQL queries, such as
select
,join
,where
,orWhere
,andWhere
,limit
, andoffset
. - Supports selecting specific columns or all columns (
*
) from a table. - Allows joining tables with different types of joins (e.g., INNER JOIN, LEFT JOIN, RIGHT JOIN).
- Enables adding WHERE clauses with various operators (e.g., '=', '>', '<', '>=', '<=').
Query Execution:
- Executes SQL queries using prepared statements to prevent SQL injection attacks.
- Fetches query results as arrays of objects for easy manipulation.
- Handles PDO exceptions and provides error handling mechanisms.
Data Manipulation:
- Supports inserting data into tables with
insert
method, providing an associative array of column names and values. - Allows updating data in tables with
update
method, providing new data as an associative array and conditions as an array of conditions. - Enables deleting data from tables with
delete
method, providing conditions as an associative array of column names and values.
Pagination:
- Implements pagination of query results using
paginate
method, allowing specification of the number of items per page and the current page number. - Calculates pagination information including total items, total pages, and current page.
- Supports seamless integration with existing query builder methods for building paginated queries.
Additional Utilities:
- Provides a
getLastQuery
method to retrieve the last executed query for debugging purposes. - Implements a
truncate
method to truncate tables, removing all rows. - Offers a
raw
method for executing raw SQL queries when needed.
Requirements
- PHP 8.0 or higher.
Installation
You can install the package via Composer by running the following command:
Sample Usage of DB
Basic Usage
Select Specific Columns
WHERE Clause
WHERE Clause with Greater Than or Equal To (>=)
WHERE Clause with Less Than or Equal To (<=)
WHERE Clause with Greater Than (>)
WHERE Clause with Less Than (<)
AND WHERE Clause
OR WHERE Clause
LIMIT
OFFSET
JOIN
INSERT
UPDATE
DELETE
Raw Query
Truncate Table
Paginate
Advanced Scenarios
The SQL builder provided is intended solely for constructing SQL queries and ensuring proper formatting. While efforts have been made to mitigate security risks, it should not be solely relied upon as a security feature. Please be aware that complex SQL queries can increase the likelihood of SQL injection vulnerabilities. It is imperative to code thoroughly and conduct thorough reviews before deploying to production environments.
Complex Nesting on WHERE CLAUSE (logic driven search)
Utilize nesting in the WHERE clause as expression, particularly for strict conditions and business logic decisions. Nesting expressions can be applied at any desired level, but excessive nesting may lead to complications. Note that keywords {{nest1}} through {{nest20}} are reserved. No other keywords or characters are allowed to nest in the nestWhereExpression method. This ensures that unwanted syntax is not welcomed in this area.
Changelog
Please see the CHANGELOG file for details on what has changed.
Security
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
Credits
DB is built and maintained by Adrian Navaja.
- Check out some cool tutorials and stuff on YouTube!
- Catch my latest tweets and updates on Twitter (formerly X)!
- Let's connect on a more professional note over on LinkedIn!
- For more information about me and my work, visit my website: sentgine.com.
- A special acknowledgment goes to Dodie Batoctoy, the esteemed Database Specialist Consultant, for significantly enhancing the capabilities of the query builder to support complex edge cases. Dodie's expertise has been invaluable to this project. For more expert insights, connect with him on (LinkedIn).
License
The MIT License (MIT). Please see the LICENSE file for more information.