droirqk4795 2018-04-28 04:31
浏览 42
已采纳

为什么这个PHP PDO Mysql代码不起作用?

I used Like operator and pass all the parameter But Still the following code is not working:

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);
    }

I am getting the following erros:

PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'LIKE '%A%' AND l.language_code = 'en'' at line 3

please help me.

  • 写回答

1条回答 默认 最新

  • duanbanzhi4419 2018-04-28 04:48
    关注

    Well looking at your error code the problem has to do with the 'LIKE' parameter, I see that you are using 'like' and 'LIKE'. I think it should look like this:

    $sql = "SELECT l.location_id, l.location_name_col FROM test_db.location_translations as l WHERE l.location_name_col LIKE :suggest AND l.language_code = :lang ";

    What if you run it again with the above code, what happens then?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助