cozy / database
A set of database tools.
Requires
- php: >=7.1.0
- ext-pdo: *
Requires (Dev)
- mockery/mockery: ~0.9
- phpunit/phpunit: ~5.4
- squizlabs/php_codesniffer: ^2.3
This package is not auto-updated.
Last update: 2025-01-05 04:49:54 UTC
README
Database toolkit for PHP 7.1+ that encapsulates a PDO instance to simplify and improve its functionality, in addition to allowing good security practices and providing an expressive query builder. This library is also a component of the Cozy PHP Framework.
Install
Via Composer
$ composer require cozy/database
Usage
Single connection to a relational database:
use \Cozy\Database\Relational\Connection; $db = new Connection('mysql:host=localhost;port=3306;dbname=test', 'user', 'password'); $account = $db ->prepare('SELECT * FROM schema.accounts WHERE id = :id') ->bindValue(':id', '6b70a1f7-2a41-4da3-9fdb-f8b60273dec1', 'string') ->fetchAsObject(Account::class);
Pool of connections to relational databases:
use \Cozy\Database\Relational\ConnectionPool; use \Cozy\Database\Relational\Connection; $db_pool = new ConnectionPool(ConnectionPool::SELECTION_RANDOM); foreach ($settings['database']['master'] as $database_info) { $db_pool->addConnection(Connection::fromArray($database_info), 'master'); } foreach ($settings['database']['slave'] as $database_info) { $db_pool->addConnection(Connection::fromArray($database_info), 'slave'); } $account = $db_pool->getConnection('slave') ->prepare('SELECT * FROM schema.accounts WHERE id = :id') ->bindValue(':id', '6b70a1f7-2a41-4da3-9fdb-f8b60273dec1', 'string') ->fetchAsObject(Account::class);
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email info@nestorpicado.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.