sshilko / php-sql-mydb
Simple yet powerful PHP wrapper for MySQL
Fund package maintenance!
sshilko
paypal.me/sergeishilko
Requires
- php: ^8.0 || ^8.1 || ^8.2
- composer-plugin-api: ^2
- ext-mysqli: *
- ext-mysqlnd: *
- ext-pcntl: *
- psr/log: ^1
Requires (Dev)
- ext-ast: *
- ext-posix: *
- composer/composer: ^2
- nikic/php-parser: ^4
- pdepend/pdepend: ^2.12
- phan/phan: ^5.4
- phpmd/phpmd: ^2.13
- phpstan/phpstan: ^1.8
- phpunit/phpunit: ^9.5
- psalm/phar: *
- slevomat/coding-standard: ^8.4
- squizlabs/php_codesniffer: ^3.8
This package is auto-updated.
Last update: 2024-12-29 09:21:03 UTC
README
MyDb - Component
Simple PHP client for MySQL database
Installation
composer require sshilko/php-sql-mydb
Compatibility
- PHP 8.0, 8.1, 8.2
- MySQL >=5.7.8, 8.0
- MariaDB not compatible (TODO)
How this client helps you talk SQL to MySQL server
- Make MySQL behave like a “traditional” SQL database system
TRADITIONAL
mode, a simple description of this mode is “give an error instead of a warning”
- Friendly transactions
autocommit = 0
- explicit
commit
on gracefull shutdown
- Explicit timeouts
- 05 seconds
client-side
connect-timeout - 89 seconds
server-side
SELECT query timeout - 90 seconds
client-side
read-timeout for any query - 7200 seconds non-interactive connection
idle timeout
mysqlnd.net_read_timeout
- respect client disconnect in php-fpm
function.ignore-user-abort.php
- 05 seconds
- Performance boost
- increased
MYSQLI_OPT_NET_READ_BUFFER_SIZE
- increased
MYSQLI_OPT_NET_CMD_BUFFER_SIZE
- read-only InnoDB optimizations
- READ COMMITED session transaction isolation level for readonly connections
- async command execution
- move mysql resultset to PHP userspace memory
MYSQLI_STORE_RESULT_COPY_DATA
- use of
fetch_all
from PHP Mysql native driver
- increased
- UTF-8
utf8mb4
character setUTC
timezone
- Quality error handling
- PHP default error-reporting
E_ALL & ~E_WARNING & ~E_NOTICE
- MySQL default error-reporting
MYSQLI_REPORT_ALL ^ MYSQLI_REPORT_STRICT ^ MYSQLI_REPORT_INDEX
SIGTERM, SIGINT, SIGHUP
signals trap- connection retry
- PHP default error-reporting
- PHPUnit & Static code analysis
- unit-tested, static analysed codebase
What is the best use-case for this library
- High performance, low-latency data-intensive applications
- No prepared statements requirement
- No 3rd party dependencies
- No run-time/compile-time steps
- Easy to start with and/or integrate into existing codebase
Out of scope
This library is not intending to become a framework, to keep focus and minimize codebase, it does not provide
- Input validation, API facade
- Object-relational mapping, ORM
- Active record pattern
- Repository pattern
- Import and export of data
please re-use existing solutions that best fit your requirements.
Why this library exists
- MySQL database is fast, reliable and scalable, php runtime is the same
- Value developers time and do not add complexity where possible
- Measure app's performance with real-world datasets and organic load
- Optimize for my use-case, focus on bottlenecks, remember that there is no
NoSQLsilver bullet - Do not optimize early - resources like CPU, memory are cheap
- Focus on building architecture, learn from others and improve over time
Future roadmap
- MariaDB compatibility layer (variables and init command syntax is different between mysql and mariadb)
- MydbFactory responsible for initializing defaults
Contributing
- Please read contributing document
Authors
Sergei Shilko contact@sshilko.com