所以根據一個建議,我試圖包括準備好的語句。變量數量不匹配參數數量 - 是的,他們做
但PHP不接受我的代碼。
$stmt = $link->prepare('SELECT COUNT(*) FROM `table` WHERE `company` = CONVERT(_utf8 \'?\' USING latin1) COLLATE latin1_german1_ci AND `password` = CONVERT(_utf8 \'?\' USING latin1) COLLATE latin1_german1_ci');
$stmt->bind_Param('ss', $firmaP, $kennwP);
$firmaP = utf8_encode($_POST['company']);
$kennwP = utf8_encode($_POST['password']);
if ($stmt->execute()) {
if($row = $stmt->fetch()) {
echo "OK";
}
else
{
echo "NO";
}
}
我得到
Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement
而我在查詢的兩個questionmarks和bind_Param兩個變量。
如何解決這個問題?
編輯:替換\'?\'?導致
Fatal error: Call to a member function bind_param() on a non-object
你不使用綁定參數時,引用字符串參數在查詢;你留下綁定語句來爲你做這件事 –
你不要引用參數。數據庫引擎會這樣做。 –
當你將它綁定到語句時,'$ firmaP'和'$ kennwP'是否有值? – datasage