Download the PHP package josecarlosphp/db without Composer
On this page you can find all versions of the php package josecarlosphp/db. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download josecarlosphp/db
More information about josecarlosphp/db
Files in josecarlosphp/db
Package db
Short Description PHP classes to interact with databases. Works with MySQL, MySQLi, and PDO.
License GPL-3.0
Homepage https://github.com/josecarlosphp/db
Informations about the package db
db
PHP classes to interact with databases. Works with MySQL, MySQLi, and PDO.
A flexible abstraction library in PHP for database interaction. It offers seamless switching between database drivers (PDO, MySQLi, MySQL), built-in transaction management, dynamic query building, automatic error recovery, and result set abstraction.
Table of Contents
- Features
- Installation
- Quick Start & Usage
- 1. Connecting to the Database
- 2. Basic CRUD Operations
- 3. Transaction Management
- 4. Working with Result Sets
- 5. Building Dynamic Queries (SqlSelectQuery)
- 6. Active Record Pattern (DbReg)
- Class Architecture
- License & Copyright
Features
- Multi-Driver Abstraction: Works transparently with
PDO,MySQLi, and legacyMySQL. - Automatic Driver Detection:
DbConnection::Factory()automatically chooses the best available driver based on PHP extensions loaded in your environment. - Transaction Management: Integrated support for starting, committing, rolling back, and checking active transactions (
beginTransaction(),commit(),rollback(),inTransaction()). - Resilient Query Execution:
- Automatic retry on MySQL deadlocks.
- Automatic reconnect handling when connection fails (
Server has gone away). - Automatic SQL mode adjustments for legacy queries.
- SQL Select Query Builder: Programmatically build complex
SELECTqueries with filters, joins, groupings, and pagination usingSqlSelectQuery. - Active Record / Table Abstraction (
DbReg): Easily map tables to object instances for CRUD operations.
Installation
Install via Composer:
Or configure your composer.json:
Or include using PSR-4 autoloading:
Quick Start & Usage
1. Connecting to the Database
Use the factory method to automatically pick the best driver (PDO, MySQLi, or MySQL):
2. Basic CRUD Operations
3. Transaction Management
Easily wrap multiple database operations in ACID transactions:
4. Working with Result Sets
Abstract result sets provide clean iteration methods:
5. Building Dynamic Queries (SqlSelectQuery)
Construct structured queries programmatically:
6. Active Record Pattern (DbReg)
Interact with database tables as objects:
Class Architecture
| Class / Component | Description |
|---|---|
DbConnection |
Abstract base class defining common interface & resilient query engine. |
DbConnection_PDO |
Driver implementation using PHP Data Objects (PDO). |
DbConnection_MySQLi |
Driver implementation using MySQLi extension functions. |
DbConnection_MySQL |
Driver implementation using legacy MySQL extension functions. |
DbResultSet |
Abstract result set wrapper with FetchAssoc(), FetchRow(), FetchAll(). |
SqlSelectQuery |
Helper class to build and manipulate SQL SELECT queries dynamically. |
DbReg |
Active record / Table ORM helper for loading, saving, and deleting records. |
License & Copyright
Copyright (C) 2019 José Carlos Cruz Parra https://github.com/josecarlosphp/
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.