這是舊版本的MySQL代碼,工程確定:轉換一個MySQL功能的mysqli
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:
爲什麼facepalming我。它也可能是一個在網頁上的電話搞砸了嗎?這裏是。
$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>";
請仔細閱讀警告,然後查看代碼的哪一部分,以確定實際連接。 – Sirko
我第二次Sirko。 –
你正在將一個SQL字符串傳遞給你的函數,作爲一個名爲'$ connection'的參數;但實際的連接似乎在$ this-> conn中。在mysqli_query()周圍交換兩個參數(並考慮將'$ connection'重命名爲更少混淆的東西) – andrewsi