bentools/mysqliextended
最新稳定版本:1.1
Composer 安装命令:
composer require bentools/mysqliextended
包简介
An enhanced MySqli class
README 文档
README
This package is abandonned. Consider upgrading to bentools/simple-dbal, which can handle PDO and Mysqli connections as well, and favors composition over inheritance.
MySqli Extended
A better experience of PHP MySqli.
Shortcuts
BenTools\MySqliExtended\MySqliExtended is a child class of \MySqli. It has several shortcut methods to fetch data :
- sqlArray() -> fetch a multi-dimensionnal array, basically several rows in a table.
- sqlRow() -> fetch an associative array, for example a row.
- sqlColumn() -> fetch the 1st column as an indexed array.
- sqlValue() -> fetch a specific value.
$cnx = new MySqliExtended(); $cnx->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5); $cnx->real_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); $query = "SELECT 'Bill' AS firstname, 'Gates' AS lastname UNION SELECT 'Tim' AS firstname, 'Cook' AS lastname"; $result = $cnx->sqlArray($query); Output: array ( 0 => array ( 'firstname' => 'Bill', 'lastname' => 'Gates', ), 1 => array ( 'firstname' => 'Tim', 'lastname' => 'Cook', ), ) $result = $cnx->sqlRow($query); Output: array ( 'firstname' => 'Bill', 'lastname' => 'Gates', ) $result = $cnx->sqlColumn($query); Output: array ( 0 => 'Bill', 1 => 'Tim', ) $result = $cnx->sqlValue($query); Output: 'Bill'
Prepared Statements
Working with prepared statements is now easier than before :
// Before : $query = "INSERT INTO `ceo` (firstname, lastname, years_in_company) VALUES (?, ?, ?)"; $stmt = $cnx->prepare($query); $firstname = 'Larry'; $lastname = 'Page'; $years_in_company = 12; $stmt->bind_param('ssi', $firstname, $lastname, $years_in_company); $stmt->execute(); // Now : $stmt = $cnx->prepare($query); $stmt->sql(array( 'Larry', 'Page', 12 )); // or directly : $cnx->sql($query, array( 'Larry', 'Page', 12 )); // or very shortly : $cnx($query, array( 'Larry', 'Page', 12 ));
You no longer need to create variables, create references and create a weird type-hinting string, i.e. 'ssi'.
You can also use named parameters (like with PDO), that you can duplicate in the same query :
$query = "INSERT INTO `ceo` (firstname, lastname, years_in_company) VALUES (:firstname, :lastname, :years_in_company) ON DUPLICATE KEY UPDATE years_in_company = :years_in_company"; $cnx->sql($query, array( 'firstname' => 'Larry', 'lastname' => 'Page', 'years_in_company' => 12 ));
Easily work with prepared statements.
$query = "SELECT firstname, lastname FROM `ceo` WHERE firstname LIKE ?"; $result = $cnx($query)->sqlRow('bill%'); Ouput : array ( 'firstname' => 'Bill', 'lastname' => 'Gates', ) $result = $cnx($query)->sqlRow('larry%'); Ouput : array ( 'firstname' => 'Larry', 'lastname' => 'Page', ) $query = "SELECT firstname, lastname FROM `ceo` WHERE (firstname LIKE :firstname OR years_in_company > :years)"; $result = $cnx($query)->sqlArray(array( 'firstname' => 'larry%', 'years' => 10 )); Output: array ( 0 => array ( 'firstname' => 'Bill', 'lastname' => 'Gates', ), 1 => array ( 'firstname' => 'Tim', 'lastname' => 'Cook', ), 2 => array ( 'firstname' => 'Larry', 'lastname' => 'Page', ), )
Installation
Add the following line into your composer.json :
{
"require": {
"bentools/mysqliextended": "1.0.x"
}
}
Enjoy.
bentools/mysqliextended 适用场景与选型建议
bentools/mysqliextended 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 83 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 07 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「mysql」 「Connection」 「mysqli」 「extended」 「mysqliextended」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bentools/mysqliextended 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bentools/mysqliextended 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bentools/mysqliextended 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
A PSR-7 compatible library for making CRUD API endpoints
Small service to parse database connection string into parts
Async, streaming plaintext TCP/IP and secure TLS socket server and client connections for HiblaPHP
统计信息
- 总下载量: 83
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-07-20