我正在我的一个类中扩展mysqli。它工作得很好,但连接增加了大约1秒的php加载时间。我想知道是否有一种更快或更合适的方式连接到MySql,或者是否有我可以构建的数据库增强功能可以更快地执行?
1秒的开销纯粹是我的WAMP服务器上的连接,这是在我运行任何其他查询之前。
有什么想法吗?
感谢
class db extends mysqli {
//ACCESS VARIABLES FOR ENTIRE SITE
protected $_host = 'myhost';
protected $_user = 'myuser';
protected $_pass = 'mypass';
protected $_db = 'mydb';
function __construct() {
echo microtime(true)."<br />";
parent::__construct($this->_host, $this->_user, $this->_pass, $this->_db);
if ($this->connect_errno) die('Connect Error: ' . $this->connect_errno);
$this->set_charset("utf8");
echo microtime(true)."<br />";
}
}
您是否尝试过删除echo
语句,看看这是否能改善运行时?
我将向您介绍Mysqli文档页面,以了解其他连接方式:http://www.php.net/manual/en/mysqli.quickstart.connections.php