我正在将我的函数从 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:
谢谢