tonix-tuft / reactphp-mysql-decorator
ReactPHP MySQL连接接口的装饰器,扩展其行为,例如提供关联参数的绑定。
v1.8.0
2021-12-27 01:53 UTC
Requires
- php: ^7.0 || ^8.0
- react/mysql: ^0.5.4
Requires (Dev)
- phpunit/phpunit: ^9.5
- tonix-tuft/testardo: ^1.1
This package is auto-updated.
Last update: 2024-09-07 04:04:40 UTC
README
ReactPHP MySQL连接接口的装饰器,扩展其行为,例如提供关联参数的绑定。
安装
使用Composer
composer require tonix-tuft/reactphp-mysql-decorator
用法
目前,唯一可用的装饰器是BindAssocParamsConnectionDecorator
,它提供了类似于标准PHP PDO
对象的关联参数绑定。
BindAssocParamsConnectionDecorator
此装饰器允许在查询中(命名参数)绑定关联参数。要使用它,只需将React\MySQL\ConnectionInterface
包装起来
<?php // ... use React\EventLoop\Factory as LoopFactory; use React\MySQL\Factory; use ReactPHP\MySQL\Decorator\BindAssocParamsConnectionDecorator; // ... $loop = LoopFactory::create(); $factory = new Factory($loop); $uri = 'username:password@localhost/dbname'; $connection = $factory->createLazyConnection($uri); // returns a React\MySQL\ConnectionInterface $connectionWithBindAssocParams = new BindAssocParamsConnectionDecorator($connection); // Now you can bind associative parameters when you execute your queries. $value = 123; $connectionWithBindAssocParams->query('SELECT * FROM table WHERE field = :value', [ ':value' => $value ])->then( // ... );
鸣谢
friends-of-reactphp/mysql - ReactPHP的异步MySQL数据库客户端。
许可证
MIT © Anton Bagdatyev (Tonix)