zhaopeng/db-read-write-separation

There is no license information available for the latest version (v1.0.1) of this package.

基于P做的数据库读写分离代码

v1.0.1 2019-10-26 13:13 UTC

This package is auto-updated.

Last update: 2025-06-27 01:59:57 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);