phpnomad / mysql-integration
Requires
- phpnomad/db: ^2.0
- phpnomad/loader: ^1.0 || ^2.0
Requires (Dev)
- phpnomad/tests: ^0.1.0 || ^0.3.0
This package is auto-updated.
Last update: 2026-04-21 13:54:02 UTC
README
phpnomad/mysql-db-integration implements phpnomad/db's query builders and table strategies for MySQL. It generates the SQL and delegates execution to a DatabaseStrategy bound in your container, so it does not open a MySQL connection on its own. Pair it with phpnomad/safemysql-integration for a ready-made driver, or supply your own if you want to run the queries through mysqli or PDO directly.
Installation
composer require phpnomad/mysql-integration
What This Provides
- A
QueryBuilderthat handles SELECT, JOIN, GROUP BY, ORDER BY, LIMIT, and OFFSET againstphpnomad/dbtables - A
ClauseBuilderfor WHERE conditions with AND/OR groups and the common comparison,LIKE,IN,BETWEEN, and null operators QueryStrategy,TableCreateStrategy,TableDeleteStrategy,TableExistsStrategy, andTableUpdateStrategyimplementations that cover insert, update, delete, query, estimated count, and schema managementDatabaseDateAdapterthat round-tripsDateTimeobjects through theY-m-d H:i:sMySQL format- A
Databasefacade exposingparse()andquery()for the boundDatabaseStrategy
Requirements
phpnomad/db ^2.0phpnomad/loader ^1.0 || ^2.0- A
PHPNomad\MySql\Integration\Interfaces\DatabaseStrategyimplementation bound in the container. Theparse()method uses SafeMySQL-style placeholders (?s,?n,?a), whichphpnomad/safemysql-integrationalready implements.
Usage
Add MySqlInitializer to your bootstrapper's initializer list and bind a DatabaseStrategy in the container before loading. The initializer registers every builder, strategy, and adapter listed above.
<?php use PHPNomad\Di\Container\Container; use PHPNomad\Loader\Bootstrapper; use PHPNomad\MySql\Integration\Interfaces\DatabaseStrategy; use PHPNomad\MySql\Integration\MySqlInitializer; use PHPNomad\SafeMySql\Integration\Strategies\SafeMySqlDatabaseStrategy; use SafeMySQL; $container = new Container(); $container->bindFactory( DatabaseStrategy::class, fn() => new SafeMySqlDatabaseStrategy(new SafeMySQL([ 'host' => '127.0.0.1', 'user' => 'myapp', 'pass' => 'secret', 'db' => 'myapp', ])) ); $bootstrapper = new Bootstrapper( $container, new MySqlInitializer() ); $bootstrapper->load();
Handlers in phpnomad/db will now resolve QueryStrategy, QueryBuilder, ClauseBuilder, and the table strategies from this package.
Documentation
The phpnomad/db documentation at phpnomad.com covers table schemas, handlers, and how the query building pipeline fits together. Placeholder semantics and connection options for the SafeMySQL driver live in the SafeMySQL repository.
License
MIT License. See LICENSE.txt.