船说cms修改代码支持mysql持久化
2024-11-29 / PHP / 89 次围观 / 0 次吐槽 /class/Db.php
public function __construct($dbarr) { $this->dbarr = $dbarr; $tmpstr = $dbarr['pconnect'] ? 'p:' : ''; // 持久化连接 try { $this->conn = new mysqli($tmpstr . $dbarr['host'], $dbarr['user'], $dbarr['pass'], $dbarr['name']); if ($this->conn->connect_error) { throw new Exception('Connection failed: ' . $this->conn->connect_error); } $this->conn->set_charset('utf8'); } catch (Exception $e) { // 捕获连接错误并输出错误信息 error_log($e->getMessage()); // 记录日志 die("Database connection failed. Please try again later."); } }
修改配置文件启用持久化
$dbarr = [ 'host' => '' ,'port' => '' ,'name' => '' ,'user' => '' ,'pass' => '' ,'pconnect' => true // 启用持久化连接 ];
Powered By Cheug's Blog
Copyright Cheug Rights Reserved.