所以根据一个建议,我试图包括准备好的陈述。
但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";
}
}
我得到了
警告:mysqli_stmt :: bind_param():变量数不匹配 准备好的陈述中的参数数量
我在查询中有两个问号,而在bind_Param中有两个变量。
如何解决这个问题?
编辑:用'替换\'?\'?导致致命错误:在非对象
上调用成员函数bind_param()
答案 0 :(得分:7)
不要引用?
如下:
$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');
$firmaP = utf8_encode($_POST['company']);
$kennwP = utf8_encode($_POST['password']);
$stmt->bind_Param('ss', $firmaP, $kennwP);
if ($stmt->execute()) {
if($row = $stmt->fetch()) {
echo "OK";
}
else
{
echo "NO";
}
}