sshilko/php-sql-mydb

Simple yet powerful PHP wrapper for MySQL

2.0.0 2024-01-03 00:07 UTC

This package is auto-updated.

Last update: 2024-05-12 23:19:15 UTC


README

Project status - active Latest Stable Version Total Downloads PHP Required Version MIT License Psalm Coverage 68747470733a2f2f686974732e736565796f756661726d2e636f6d2f6170692f636f756e742f696e63722f62616467652e7376673f75726c3d68747470732533412532462532466769746875622e636f6d253246737368696c6b6f2532467068702d73716c2d6d79646226636f756e745f62673d253233373943383344267469746c655f62673d2532333535353535352669636f6e3d2669636f6e5f636f6c6f723d253233453745374537267469746c653d6869747326656467655f666c61743d66616c7365 Code size
PHPUnit coverage PHPUnit classes coverage PHPUnit lines coverage PHPUnit methods coverage
8.1 Phan build 8.1 Psalm build 8.1 PHPMd build 8.1 PHPStan build 8.1 PHPCodeSniffer build 8.1 PHPDocumentor build 8.1 Pdepend build 8.1 PHPUnit build 8.0 PHPUnit build 8.1 PHPUnit build 8.2 PHPUnit build GithubPages build

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
  • Friendly transactions
  • 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
  • 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
  • UTF-8
    • utf8mb4 character set
    • UTC 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
  • 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

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 NoSQL silver 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

Authors

Sergei Shilko contact@sshilko.com