readdle/fqdb

4.2.0 2022-09-06 12:37 UTC

This package is auto-updated.

Last update: 2024-11-06 17:07:45 UTC


README

Wrapper for PDO with specific DB operations and more checks. Available via composer.

Latest Stable Version Total Downloads License Build Status

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.