无法使用带有字符串字段的Where子句搜索数据库

时间:2014-03-09 12:02:25

标签: php mysql

我正在使用以下代码

public static function getRecord($query){ // Gets single record and returns single associative array
        db::open();
        $result = mysql_query($query) or die(mysql_error());
        if(!mysql_num_rows($result)==0){
            $recordset = mysql_fetch_assoc($result);
            }else{
                $recordset = false;
            }
        db::close();
        return ($recordset);
    }

$query = "SELECT * FROM callDetails WHERE storeName = " . $name ;  

我收到此错误

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 'E Jewelers LIMIT 0, 50' at line 1

$ name是'A E Jewelers'

1 个答案:

答案 0 :(得分:2)

$query = "SELECT * FROM callDetails WHERE storeName = '" . $name ."'";