gpt4 book ai didi

php - 如何将功能从使用 mysql 更改为 mysqli

转载 作者:行者123 更新时间:2023-11-30 00:45:33 25 4
gpt4 key购买 nike

我正在为我的 cms 切换到 mysqli,并且在将查询和获取功能切换到 mysqli 时遇到一些问题,我不断收到这样的错误

Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /home/u250000297/public_html/forum/system/db.php on line 48 Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/u250000297/public_html/forum/system/db.php on line 49 Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /home/u250000297/public_html/forum/system/db.php on line 48 Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/u250000297/public_html/forum/system/db.php on line 49  Warning: mysqli_real_query() expects parameter 1 to be mysqli, null given in /home/u250000297/public_html/forum/system/db.php on line 41 Warning: mysqli_error() expects parameter 1 to be mysqli, null given in /home/u250000297/public_html/forum/system/db.php on line 41

我尝试过不同的要求,如下所示:

function query($query) {
$sql = mysqli_real_query($connection, $query) or die (mysqli_error($connection));
return $sql;
mysqli_free_result($sql);

}

function fetch($query) {
$data = mysqli_query($connection, $query);
mysqli_fetch_array($data);
return($data);
}

2:
function query($query) {
$sql = mysqli_query($this->db, $query) or die(mysqli_error());
return $sql;
mysqli_free_result($sql);

}

function fetch($query) {
$data = mysqli_query($this->db, $query);
mysqli_fetch_array($data);
return($data);
}

我一直遇到同样的错误,我不知道我是否做错了什么。你能帮助我并给我一些提示吗?,我在尝试使用 mysqli 之前的原始代码

function query($query) {
$sql = mysql_query($query, $this->db) or die(mysql_error());
return $sql;
mysql_free_result($sql);
}



function fetch($query) {
$sql = mysql_fetch_array(mysql_query($query, $this->db));
return $sql;
mysql_free_result($sql);

}

最佳答案

首先建立连接和数据库名称

$this->con = mysqli_connect($this->host,$this->user,$this->pass);
mysqli_select_db( $this->con,$this->db );

然后像这样执行查询

function query_execute( $query )
{
$this->query = mysqli_query( $this->con,$query );
if ($this->query->num_rows > 0 ) {
return $this->query;
} else {
return mysqli_error( $this->con );
}
}

关于php - 如何将功能从使用 mysql 更改为 mysqli,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21397174/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com