我正在使用mysqli prepare语句来查询具有多个约束的数据库。我已经在我的测试文件中运行了代码,并且它工作得很好。然而,当我在我的直播移动文件的代码,它抛出的错误如下:PHP mysqli编写语句不起作用
PHP的警告:)mysqli_stmt :: bind_result(:绑定变量的数目 不会在事先准备好的声明匹配字段数 C:\瓦帕\ WWW \ firecom \ firecom.php线80上
PHP说明:未定义变量:导致 C:\瓦帕\ WWW \ firecom \ firecom.php上线89
两个参数都被正确设置,但有些东西正在抛弃它。
代码:
$query = $mysqli->prepare("SELECT * FROM calls WHERE wcccanumber = ? && county = ?");
$query->bind_param("ss", $wcccanumber, $county);
$query->execute();
$meta = $query->result_metadata();
while ($field = $meta->fetch_field()) {
$parameters[] = &$row[$field->name];
}
call_user_func_array(array($query, 'bind_result'), $parameters);
while ($query->fetch()) {
foreach($row as $key => $val) {
$x[$key] = $val;
}
$results[] = $x;
}
print_r($results['0']);
$查询的var_dump:
object(mysqli_stmt)#27 (10) { ["affected_rows"]=> int(-1) ["insert_id"]=> int(0) ["num_rows"]=> int(0) ["param_count"]=> int(2) ["field_count"]=> int(13) ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["sqlstate"]=> string(5) "00000" ["id"]=> int(1) }
你可以使用&&在SQL查询?我认为这是在WHERE子句中。尝试SELECT * FROM调用WHERE wcccanumber =? AND县=? –
@JeffHawthorne实际上'&&'是mysql中AND的同义词:http://dev.mysql.com/doc/refman/5.0/en/logical-operators.html#operator_and –
'$ results'警告很简单 - 服务器正在检查未定义的变量,而你的本地变量不是。在while($ query-> fetch())'循环之前定义'$ results',它会消失。 –