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 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题