这是可以正常工作的旧 MySQL 代码:
function getResult($sql) {
$result = mysql_query($sql, $this->conn);
if ($result) {
return $result;
} else {
die("SQL Retrieve Error: " . mysql_error());
}
}
但是,我尝试将其更改为 mysqli。这就是我目前所处的位置。
function getResult($connection){;
$result = mysqli_query($connection, $this->conn); //L92
if ($result) {
return $result;
} else {
die("SQL Retrieve Error: " . mysqli_error($connection)); //L96
}
}
可怕的消息正在发生:
Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\xampp\htdocs\sotdhit\dogsfunc.php on line 92
Warning: mysqli_error() expects parameter 1 to be mysqli, string given in C:\xampp\htdocs\sotdhit\dogsfunc.php on line 96
SQL Retrieve Error:
为什么它在我面前打脸。网页上的通话是否也可能是一团糟?这里是。
$db1 = new dbmember(); //name of the class
$db1->openDB();
$sql="SELECT * from member";
$result=$db1->getResult($sql);
echo "<table border='1'>";
echo "<tr><th>Member ID</th><th>Name</th><th>Address</th><th>Postcode</th><th>Photo</th></tr>";
while($row = mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<td>{$row['mid']}</td><td>{$row['name']}</td>";
echo "<td>{$row['address']}</td><td>{$row['postcode']}</td>";
echo"<td><img height='80' width='120' src='{$row['photo'] }' /></td>";
echo "</tr>";
}
echo "</table>";