gpt4 book ai didi

php - 函数 getResult 调用

转载 作者:行者123 更新时间:2023-11-29 08:27:38 27 4
gpt4 key购买 nike

我正在努力将我的函数从 MySQL 转移到 MySQLi 标准。

这是我以前的 getresult 函数

  function getResult($sql) {
$result = mysql_query($sql, $this->conn);
if ($result) {
return $result;
} else {
die("SQL Retrieve Error: " . mysql_error());
}
}

但是,我一直在关注W3schools上的mysqli_query函数。这就是我现在所在的位置。

 function getResult($connection){
$result = mysqli_query($connection->conn);
if ($result) {
return $result;
} else {
die("SQL Retrieve Error: " . mysqli_error());
}
}

现在,W3schools 上的示例与我想要使用 mysqli_query 的方式略有不同。我试图让它针对我的数据库,而不是 W3S 上的示例中的一些输入或常量。

Notice: Trying to get property of non-object in C:\xampp\htdocs\cad\func.php on line 92

Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\xampp\htdocs\cad\func.php on line 92

Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\cad\func.php on line 96
SQL Retrieve Error:

谢谢

最佳答案

由于多种原因,您的版本无法运行,其中最重要的原因是您没有包含要发送的查询。假设 $this->conn 设置正确,请尝试以下操作:

 function getResult($sql) {
$result = mysqli_query($this->conn, $sql); //Note parameters reversed here.
if ($result) {
return $result;
} else {
die("SQL Retrieve Error: " . mysql_error());
}
}

关于php - 函数 getResult 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17517058/

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