readdle / fqdb
4.2.0
2022-09-06 12:37 UTC
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
PDO 特定数据库操作和更多检查的包装器。可通过 composer 获取。
实例化
直接创建 FQDB 实例
$fqdb = new \Readdle\Database\FQDB('mysql:host=localhost;dbname=test', 'user', 'password');
通过 FQDBProvider 创建 FQDB 实例
// 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);
使用示例
$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 为不同的 SQL 查询提供独立的方法。如果 SQL 查询和方法名称不匹配,则抛出异常。
- 插入
- 删除
- 替换
- 更新
- 设置
- 选择并显示(查询值,查询列表,查询向量,查询关联,查询表,查询对象,查询对象数组,查询表回调,查询表生成器,查询哈希)
FQDB 使用 PDO 命名参数,并进行了额外的检查以确认未使用参数和未绑定参数。
对于 MySQL 驱动,FQDB 允许可选地报告警告,将 MySQL 警告作为 PHP 警告发出。