我一直使用PDO语句,但由于某些原因,我无法说服服务器人员安装用于php的PDO,但我确实有MySQLi,我不知道我做错了什么,我没有得到连接错误,无论我如何输出,我都没有得到查询错误。这就是我正在做的。
include 'MySQLiConnect.php';
if($stmt = $mysqli->prepare("SELECT * FROM zipCodeTable WHERE zip_code = ?")){
$stmt->bind_param("s", '07110');
$stmt->execute();
$stmt->bind_result($resultsArray);
$stmt->fetch();
foreach($resultsArray as $columnData){
$matchingZipcode = $columnData['zip_code'];
$matchingTimezone = $columnData['time_zone'];
}
$stmt->close();
}
echo $matchingZipcode.', '.$matchingTimezone;
这基本上只是为了确认用户的zipcode,以前从未使用过MySQLi准备的语句,我尝试直接从手册中进行,不确定我做错了什么。感谢您花时间阅读本文。
您正在尝试"绑定"一个文本字符串。你不能这样做。您必须绑定一个变量。
更改
$stmt->bind_param("s", '07110');
至
$string = '07110';
$stmt->bind_param("s", $string);
此外,绑定结果时,必须为返回的每个字段提供一个变量。
例如:
$stmt->bind_result($zipCode, $timeZone);
当使用SELECT *
时,这有点问题。你可能有兴趣查看这条评论,了解你可能想怎么做:http://www.php.net/manual/en/mysqli-stmt.bind-result.php#85470