原因:是因为DB_Mysql.class.php里,连接以及操作数据库的相关方法都已废弃。
例如:mysql_connect、mysql_fetch_array、mysql_insert_id等方法都已废弃。
解决方法:在DB_Mysql.class.php文件里替换成新的方法。
如果无效,检查你的xampp工具版本,php版本。本人的xampp版本是3.2.4,里面的php版本是8.0,太旧的自己更新去吧嘻嘻。
/**
* @ DB_Mysql.class.php
* @ zmouse@vip.qq.com
*/
defined('IN_APP') or exit('Denied Access!');
class DB_Mysql implements DBInterface {
private static $instanceObj;
private $config = array();
private $conn = null;
private function __construct($config) {
$this->config = $config;
$this->connect();
}
public static function instance($config) {
if (!self::$instanceObj) {
$c = __CLASS__;
self::$instanceObj = new $c($config);
}
return self::$instanceObj;
}
public function connect() {
// $this->conn = new mysqli($this->config['db_host'], $this->config['db_user'], $this->config['db_password'], $this->config['db_name']);
$this->conn = new mysqli("127.0.0.1:3306", "root", "", "miaov_guestbook");
if (!$this->conn) {
$this->halt('链接数据库失败!');
// die("连接失败: " . mysqli_connect_error());
}
$this->query("SET NAMES 'utf8'");
// if (!$this->conn = new mysqli($this->config['db_host'], $this->config['db_user'], $this->config['db_password'], $this->config['db_name'])) $this->halt('链接数据库失败!');
// mysql_select_db($this->config['db_name'], $this->conn);
// $this->query("SET NAMES 'utf8'");
// if (!$this->conn = @mysql_connect($this->config['db_host'], $this->config['db_user'], $this->config['db_password'])) $this->halt('链接数据库失败!');
// mysql_select_db($this->config['db_name'], $this->conn);
// $this->query("SET NAMES 'utf8'");
}
public function query($sql) {
return mysqli_query($this->conn,$sql);
// return mysql_query($sql);
}
public function select($sql, $num=0, $mode=1) {
if ($num) $sql .= " LIMIT {$num}";
$query = $this->query($sql);
$rs = $result = array();
while ($result = mysqli_fetch_array($query, $mode)) {
$rs[] = $result;
}
return $rs;
}
public function get($sql, $mode=1) {
$rs = $this->select($sql, 1, $mode);
return isset($rs[0])? $rs[0] : false;
}
public function getInsertId() {
return mysqli_insert_id($this->conn);
}
private function halt($msg, $exit=true) {
if ($exit) {
exit('
' . $msg . '
');} else {
echo '
' . $msg . '
';}
}
}
效果图: