简体   繁体   中英

Why this PHP PDO Mysql code not working?

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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM