我使用mysqli
來執行db查詢。這是我的代碼:綁定中的參數與綁定字段的數量不匹配?
if($stmt = $connection->prepare("SELECT * FROM table1 WHERE code = ?"))
{
$find = "Op";
$stmt->bind_param("s", $find);
$stmt->execute();
$stmt->bind_result($res);
$stmt->fetch();
echo "Res => " . $res;
$stmt->close();
}
現在的問題是,在這條線:$stmt->bind_param("s", $find);
我得到這個錯誤:
Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables
注:$connection
包含與數據庫建立連接。我做錯了什麼?
你'bind_param()'是好的。問題出在'$ stmt-> bind_result($ res);'。將'SELECT'語句從'SELECT * FROM ...'更改爲'SELECT column1 FROM ...' –
@RajdeepPaul好吧,如果我設置了一個特定的列,如'SELECT column_name'工作,我想'bind_result'我應該設置我想從數據庫中檢索的確切列數?稍後,重複一遍。 – Sandokan
是的,這是正確的。 –