php代码报错,关于php代码报错问题,解决方法

原因:是因为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 . '

';

}

}

}

效果图:

6a6102d95f4117762de80043e17ada53.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值