zhaopeng / db-read-write-separation
此包的最新版本(v1.0.1)没有可用的许可信息。
基于P做的数据库读写分离代码
v1.0.1
2019-10-26 13:13 UTC
This package is auto-updated.
Last update: 2024-09-27 00:16:13 UTC
README
基于Pdo做的主从分离器
配置文件基于不同的框架来做,项目中没有固定的配置格式
项目封装了pdo对象,没有封装具体的CURD代码,需要自行扩展,只需在MysqlConnection中扩展即可
use dbrw\connectors\ConnectionFactory;
$sql = 'select * from user_account where uid=1';
$factory = new ConnectionFactory(); $connect = $factory->createConnection([ 'driver' => 'mysql', 'host' => '127.0.0.1', 'port' => 3306, 'database' => 'test', 'username' => 'admin', 'password' => '123456', ], false);
$pdo = $connect->getPdo();
$connect->filter($sql); // 过滤sql
$res = $pdo->query($sql)->fetch(); var_dump($res);