yiisoft / db-mysql
Yii DataBase MySQL Extension
Fund package maintenance!
Open Collective
yiisoft
Installs: 38 518
Dependents: 6
Suggesters: 0
Security: 0
Stars: 28
Watchers: 13
Forks: 11
Open Issues: 5
Requires
- php: ^8.0
- ext-ctype: *
- ext-json: *
- ext-pdo: *
- psr/log: ^2.0|^3.0
- yiisoft/db: ^3.0@dev
- yiisoft/json: ^1.0
Requires (Dev)
- maglnet/composer-require-checker: ^4.2
- phpunit/phpunit: ^9.5
- rector/rector: ^0.14
- roave/infection-static-analysis-plugin: ^1.16
- spatie/phpunit-watcher: ^1.23
- vimeo/psalm: ^4.18
- yiisoft/aliases: ^2.0
- yiisoft/cache: ^2.0
- yiisoft/cache-file: ^2.0
- yiisoft/log-target-file: ^2.0
This package is auto-updated.
Last update: 2023-01-30 22:24:44 UTC
README
Yii DataBase MySQL Extension
Yii Database MySQL Extension is a database extension for the Yii Framework that allows developers to access and interact with MySQL and MariaDb databases. It provides a set of classes and methods for connecting to a MySQL and MariaDb database, executing SQL queries, and managing data within the database. The extension is designed to be easy to use and integrate into Yii-based applications, and supports a wide range of MySQL, MariaDb features and functions. It also includes support for transactions, database schema management, and error handling.
It is used in Yii Framework but can be used separately.
Support version
PHP | Mysql/MariaDb | CI-Actions |
---|---|---|
8.0-8.2 | 5.7-8.0/10.4-10.10 |
Installation
The package could be installed via composer:
composer require yiisoft/db-mysql
Config with Yii Framework
The configuration with DI container of Yii Framework.
Also you can use any DI container which implements PSR-11.
db.php
<?php declare(strict_types=1); use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Mysql\ConnectionPDO; use Yiisoft\Db\Mysql\PDODriver; /** @var array $params */ return [ ConnectionInterface::class => [ 'class' => ConnectionPDO::class, '__construct()' => [ 'driver' => new PDODriver( $params['yiisoft/db-mysql']['dsn'], $params['yiisoft/db-mysql']['username'], $params['yiisoft/db-mysql']['password'], ), ] ] ];
params.php
<?php declare(strict_types=1); use Yiisoft\Db\Mysql\Dsn; return [ 'yiisoft/db-mysql' => [ 'dsn' => (new Dsn('mysql', '127.0.0.1', 'yiitest', '3306', ['charset' => 'utf8mb4']))->asString(), 'username' => 'user', 'password' => 'password', ] ];
Config without Yii Framework
<?php declare(strict_types=1); use Yiisoft\Cache\ArrayCache; use Yiisoft\Cache\Cache; use Yiisoft\Db\Cache\SchemaCache; use Yiisoft\Db\Mysql\ConnectionPDO; use Yiisoft\Db\Mysql\Dsn; use Yiisoft\Db\Mysql\PDODriver; // Or any other PSR-16 cache implementation. $arrayCache = new ArrayCache(); // Or any other PSR-6 cache implementation. $cache = new Cache($arrayCache); $dsn = (new Dsn('mysql', '127.0.0.1', 'yiitest', '3306', ['charset' => 'utf8mb4']))->asString(); // Or any other PDO driver. $pdoDriver = new PDODriver($dsn, 'user', 'password'); $schemaCache = new SchemaCache($cache); $db = new ConnectionPDO($pdoDriver, $schemaCache);
Unit testing
The package is tested with PHPUnit. To run tests:
./vendor/bin/phpunit
Mutation testing
The package tests are checked with Infection mutation framework. To run it:
./vendor/bin/infection
Static analysis
The code is statically analyzed with Psalm. To run static analysis:
./vendor/bin/psalm
Rector
Use Rector to make codebase follow some specific rules or use either newest or any specific version of PHP:
./vendor/bin/rector
Composer require checker
This package uses composer-require-checker to check if all dependencies are correctly defined in composer.json
.
To run the checker, execute the following command:
./vendor/bin/composer-require-checker
Support the project
Follow updates
License
The Yii DataBase MySQL Extension is free software. It is released under the terms of the BSD License.
Please see LICENSE
for more information.
Maintained by Yii Software.