noahheck/e_mysqli
Composer 安装命令:
composer require noahheck/e_mysqli
包简介
Replacement for default Mysqli class to allow viewing a parameterized query with the arguments inserted into the string
README 文档
README
Replacement for default Mysqli class to allow viewing a parameterized query with the arguments inserted into the string
View the changelog
Usage
Provides similar functionality to that found in the PDO sister project:
Not being able to view a complete version of the query to be executed on the server after statement parameters have been interpolated can be frustrating.
EMysqli aims to ease this burden by providing developers the ability to view what would be an example of the query executed on the server:
$query = "INSERT INTO registration SET name = ?, email = ?"; $stmt = $mysqli->prepare($query); $name = $_POST['name']; $email = $_POST['email']; $stmt->bind_param("ss", $name, $email); $stmt->execute(); echo $stmt->fullQuery;
The result of this will be:
INSERT INTO registration SET name = 'John Doe', email = 'john.doe@example.com'
When used correctly, the interpolated values are escaped appropriately according to character set in use on the database server:
INSERT INTO registration SET name = 'Sue O\'Reilly', email = 'sue.o@example.com'
It's also possible to view the interpolated query string without executing the query:
$query = "INSERT INTO registration SET name = ?, email = ?"; $stmt = $mysqli->prepare($query); $name = $_POST['name']; $email = $_POST['email']; $stmt->bind_param("ss", $name, $email); $fullQuery = $stmt->interpolateQuery();// INSERT INTO registration SET name = 'John Doe', email = 'john.doe@example.com'
Further Enhancements
A (fortunate ?) side effect of the way EMysqli performs it's work also allows you to bind multiple parameters individually, helpful if your query string is generated in separate method/function calls.
This is accomplished by binding the parameters individually:
$name = $_POST['name']; $email = $_POST['email']; $stmt->bind_param("s", $name); $stmt->bind_param("s", $email);
Note
Using either of these two methods stores the bound parameters as references to their runtime variables preventing the need to rebind parameters, which is the default method for handling bound parameters in mysqli:
$name = "John Doe"; $email = "john.doe@example.com"; $stmt->bindParam("s", $name); $stmt->bindParam("s", $email); $stmt->execute(); // INSERT INTO registration SET name = 'John Doe', email = 'john.doe@example.com' $name = "Sue O'Reilly"; $email = "sue.o@example.com"; $stmt->execute(); // INSERT INTO registration SET name = 'Sue O\'Reilly', email = 'sue.o@example.com'
Installation
Install via composer:
composer require noahheck/e_mysqli
Configuration
E_mysqli extends both the mysqli and mysqli_stmt classes. Your mysqli object creation process will simply need to be updated to generate an instance of EMysqli\EMysqli instead:
<?php require_once "path/to/vendor/autoload.php"; $mysqli = new EMysqli\EMysqli($dbHost, $dbUser, $dbPassword, $dbName);
That's all there is to it. Your $mysqli object should function the same as it has.
Feedback Request
The E_PDOStatement project has received some good feedback, and a common request was to offer the same or similar functionality to users still using mysqli. Though I have no practical experience using the myslqi extension, I have researched how this might be possible and this is what I have managed to come up with.
As I have no production quality application code to test this extension on, any feedback regarding performance in a production setting would be appreciated. Bugs, new feature requests and pull requests are of course welcome.
noahheck/e_mysqli 适用场景与选型建议
noahheck/e_mysqli 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 175 次下载、GitHub Stars 达 10, 最近一次更新时间为 2016 年 11 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sql」 「debug」 「mysql」 「query」 「debugger」 「mysqli」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 noahheck/e_mysqli 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 noahheck/e_mysqli 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 noahheck/e_mysqli 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Debug your SimpleBus EventBus and CommandBus
nice output for debug functions for PHP 5.3
Query filtering in your frontend
Analysis module for finding problematical shop data.
Twig extensions for Tracy Debugger
统计信息
- 总下载量: 175
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2016-11-07