2013-02-09 145 views
3

我一直使用PDO语句,但出于某种原因,我无法说服服务器人员为php安装PDO,但我确实有MySQLi,我不知道我做错了什么,我不要收到连接错误,不管我怎么输出一个错误,都不会收到查询错误。这是我正在做的。准备好的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; 

这基本上只是为了确认用户的邮政编码,从来没有使用过的MySQLi准备语句之前,我tryed从手动直做到这一点,不知道我做错了。感谢您抽出时间来阅读。

+2

如果您的“服务器人员”不允许您使用PDO,则需要新的服务器人员。 – ceejayoz 2013-02-09 19:28:09

+0

不是答案,但为什么要在表格中附加“Table”? – PeeHaa 2013-02-09 19:30:22

+0

@ceejayoz我在帮朋友出去,他们给了我一些半屁股托管的云机做这个愚蠢的邮政编码确认lol – user1053263 2013-02-09 19:32:25

回答

3

你试图“绑定”一个文字字符串。你不能这样做。你必须绑定一个变量。

变化

$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

+0

哦,好吧,现在有道理!像魅力一样工作,非常感谢你! – user1053263 2013-02-09 19:39:14