Download the PHP package ocallit/sqler without Composer
On this page you can find all versions of the php package ocallit/sqler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ocallit/sqler
More information about ocallit/sqler
Files in ocallit/sqler
Package sqler
Short Description A php sql builder, helpers and mysqli wrapper
License MIT
Informations about the package sqler
Sqler - PHP Database Access Library
- A php sql builder, database & query metadata, auditor, helpers and mysqli wrapper.
- A powerful, feature-rich PHP database access layer built on MySQLi, providing intelligent query building, comprehensive error handling, database metadata introspection, and complete audit trail functionality.
Key Features
- 🔄 Intelligent Error Recovery - Automatic retry on deadlocks, timeouts, and connection issues
- 🛡️ Robust Error Handling - Comprehensive exception handling with specific error type detection
- 📊 Multiple Result Formats - Get data in the shape you need: single values, rows, arrays, key-value pairs
- 🔍 Database Introspection - Complete metadata access for tables, columns, relationships
- 📝 Audit Trail System - Full change tracking with diff analysis and user attribution
- ⚡ Smart Query Building - Parameterized queries with MySQL function recognition
- 🔒 Transaction Management - Nested transaction support with automatic cleanup
- 📋 Query & Error Logging - Comprehensive logging for debugging and monitoring
AI Assistant Documentation
For AI assistants and comprehensive API reference: See Sqler_AI_DOCUMENTATION.md - This contains detailed method signatures, return types, usage patterns, and examples specifically formatted for AI assistance.
Installation & Quick Start
Requirements
- PHP 8.2+
- MySQLi extension
- MySQL 5.7+ / MariaDB 10.2+
Installation via Composer
Basic Usage
Core Components
SqlExecutor - Database Query Engine
The heart of the library, providing multiple ways to execute and retrieve data:
Which server is it (MySQL or MariaDB) and which collation to use:
The server is asked once per connection. collationAiCi() only returns a collation the server really has (it checks information_schema.COLLATIONS).
Error Handling with Smart Recovery:
QueryBuilder - Safe Query Construction
Build parameterized queries with automatic escaping and MySQL function recognition:
DatabaseMetadata - Schema Introspection
Get complete information about your database structure:
Historian - Complete Audit Trail
Track all changes with automatic diff analysis:
Advanced Features
Transaction Management
Error Recovery & Logging
Configuration Options
SqlExecutor Configuration
QueryBuilder Options
Best Practices
- Always use parameterized queries - The library handles this automatically
- Initialize DatabaseMetadata once at application startup
- Use appropriate result methods based on expected data shape
- Implement proper error handling with specific error type checking
- Close connections properly in finally blocks
- Use transactions for multi-query operations
- Leverage audit trails for compliance and debugging
Error Handling Reference
The library provides specific error detection methods:
is_last_error_table_not_found()- Missing tablesis_last_error_duplicate_key()- Unique constraint violationsis_last_error_invalid_foreign_key()- Invalid foreign key referencesis_last_error_child_records_exist()- Cannot delete parent with childrenis_last_error_column_not_found()- Invalid column names
Recommended catch shape
Every database, connect and option failure is a mysqli_sql_exception.
Assumes PHP 8.3+ with MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT (the PHP default).
Things the caller must know:
firstValue()returns a scalar, and$defaultwhen no row matches. To tell "no row" from an empty or NULL value, pass a$defaultthat the column can never hold. If the column is nullable and allows every value, userow()and test for[]instead.firstValue,row,array,arrayKeyed,multiKey*,keyValueandvectorneed a statement that returns a result set (SELECT). Calling them with INSERT/UPDATE/DELETE/DDL throws\Error; usequery().query()returnstruefor DML. An UPDATE matching 0 rows is not an error: checkaffected_rows().last_insert_id()is0when nothing was inserted. WithON DUPLICATE KEY UPDATEit only returns the key if you useid = LAST_INSERT_ID(id).- Code 2006/2013 thrown while
COMMITran means the outcome is unknown:isCommitOutcomeUnknown()is true and the transaction was not retried. Check the database before running it again.rollback()does not clear it. - Parameters must be a list array (
[1, 'a']), not named keys, or\ValueErroris thrown.
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please ensure:
- PHP 8.2+ compatibility
- Comprehensive error handling
- Unit tests for new features
- Documentation updates
Support
For issues, feature requests, or questions, please use the GitHub issue tracker.
All versions of sqler with dependencies
ext-mysqli Version *
ext-bcmath Version *
ext-intl Version *