这段代码怎么会出错?

时间:2014-06-21 18:48:34

标签: php mysql binary

我一直收到这个错误,我非常肯定我的语法是正确的!

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '='00001010'' at line 1

PHP代码:

<?php
$decode = str_split($_POST['ascii'], 8);
mysql_connect("localhost","Username","Password");
mysql_select_db("information");
foreach($decode as $char){
    $query = mysql_query("SELECT * FROM ascii_binary WHERE binary='$char'") or die(mysql_error());
    while ($row = mysql_fetch_array($query)) {
        $char = $row['character'];
        echo $char;
    }
}
?>

2 个答案:

答案 0 :(得分:1)

你必须在BINARY周围使用反引号,因为BINARY是mysql的保留关键字。

像那样:

 SELECT * FROM ascii_binary WHERE `binary` ='$char'

答案 1 :(得分:0)

BINARY是MySQL中的保留关键字。可能这就是你错误的原因。因此,请尝试在MySQL数据库中重命名列。