为什么此PHP PDO MySQL代码不起作用



我使用的是运算符并传递所有参数,但仍然无法正常工作:

public function get_locations($lang, $suggest){
        $this->lang = $lang;
        $this->suggest = $suggest;
        $sql = "SELECT l.location_id, l.location_name_col 
                FROM test_db.location_translations as l
                WHERE l.location_name_col like LIKE :suggest
                AND   l.language_code = :lang
                ";
         $params = array(':suggest'=>"%".$this->suggest."%", ':lang'=> $this->lang);
        $stmt = $this->conn->prepare($sql);            
        $stmt->execute($params);
    }

我得到以下erros:

pdoexception'带有消息'sqlstate [42000]:语法错误或访问 违规:1064您的SQL语法有错误;检查手册 对应于您的MariadB服务器版本的正确语法 使用接近"%a%" 和L.Language_code ='en''在第3行

请帮助我。

好看您的错误代码与'like'参数有关,我看到您正在使用'like''and'like'。我认为应该看起来像这样:

$ sql =" select l.location_id,l.l.location_name_col test_db.location_translations作为l l.location_name_col喜欢 :建议和L.language_code =:lang";

如果您使用上述代码再次运行它,那会发生什么?

最新更新