phpmysqlcodeigniter-3mysql-error-1064where-in

CodeIgniter SELECT query with empty IN() condition in WHERE clause gives error 1064


I tried to join multiple tables and got the following error:

A Database Error Occurred Error Number: 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 ') ORDER BY `table1`.`value` ASC' at line 4

SELECT `table1`.* FROM `table1` LEFT JOIN `table2` ON `table2`.`id`=`table1`.`id` WHERE `table1`.`p_id` IN() ORDER BY `table1`.`value` ASC

Filename: C:/xampp/htdocs/limca/system/database/DB_driver.php

Line Number: 691

How to solve this error?


Solution

  • Add some values inside WHERE IN(?)

    SELECT `table1`.* FROM `table1` 
    LEFT JOIN `table2` ON `table2`.`id`=`table1`.`id` 
    WHERE `table1`.`p_id` IN(?) ORDER BY `table1`.`value` ASC