readdle / fqdb
Installs: 47 733
Dependents: 1
Suggesters: 0
Security: 0
Stars: 5
Watchers: 9
Forks: 4
Open Issues: 0
Requires
- php: >=7.4
- ext-json: *
- ext-pdo: *
- symfony/event-dispatcher-contracts: ^2.0|^3.0
Requires (Dev)
- escapestudios/symfony2-coding-standard: ^3.12
- jangregor/phpstan-prophecy: ^1.0
- pheromone/phpcs-security-audit: ^2.0
- phpcompatibility/php-compatibility: ^9.3
- phpspec/prophecy-phpunit: ^2.0
- phpstan/phpstan: ^1.8
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- slevomat/coding-standard: ^8.4
- squizlabs/php_codesniffer: ^3.6
README
Wrapper for PDO with specific DB operations and more checks. Available via composer.
Instantiating:
Create FQDB instance directly
$fqdb = new \Readdle\Database\FQDB('mysql:host=localhost;dbname=test', 'user', 'password');
Create FQDB instance via FQDBProvider
// parses ~/.my.cnf $fqdb = FQDBProvider::dbWithMyCnf($database); // dsn example: mysql:host=127.0.0.1;dbname=database;charset=utf8mb4 $fqdb = FQDBProvider::dbWithDSN($dsn, $user, $password); $fqdb = FQDBProvider::dbWithMySQLHostUserPasswordDatabase($host, $user, $password, $database);
Examples of usage:
$fqdb = new \Readdle\Database\FQDB('mysql:host=localhost;dbname=test', 'user', 'password'); $value = $fqdb->queryValue("SELECT 2+2"); // $value == 4 $hash = $fqdb->queryAssoc("SELECT id, content FROM idcontent WHERE id=13"); // $hash = ['id' => 13, 'content'=>'...'] // to use a custom connector you can register it before instantiating the FQDB \Readdle\Database\FQDB::registerConnector(\Readdle\Database\ConnectorInterface $connector); $fqdb = new \Readdle\Database\FQDB($optionSupportedByYourConnector);
FQDB has separate methods for different SQL queries. It throws exception if SQL query and method name does not match.
- insert
- delete
- replace
- update
- set
- select and show (queryValue, queryList, queryVector, queryAssoc, queryTable, queryObj, queryObjArray, queryTableCallback, queryTableGenerator, queryHash)
FQDB uses PDO named parameters with additional checks for unused parameters and unbind parameters.
For MySQL driver FQDB has optional warning reporting that emits MySQL warnings as PHP warnings.