💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
``` <?php // 定义为开启主从的开关 define('swich',true); class DB { public $pdo; public $readPdo; public function __construct() { // 主数据库(主要是写入) $this->pdo = new PDO('mysql:host=localhost;dbname=lamp129;charset=utf8','root',''); // 从数据库(主要是查询) if ($this->swich) { $this->readPdo = new PDO('mysql:host=192.168.129.251;dbname=lamp129;charset=utf8','root',''); } else { $this->readPdo = $this->pdo; } } // 查询 public function select() { $this->readPdo->query('select * from user'); } // 添加操作 public function insert() { $this->pdo->exec('insert into user(username) values("zhangsan")'); } } ```