i m trying to add this query into my code in laravel. it runs smoothly in phpmyadmin or with mysql command line but enable to get anything but this syntax error.
my query :
$query_sql=" CREATE TEMPORARY TABLE F as( SELECT * from ( select M.* ,M2.idA from ( SELECT o.id , o_n.id_n as idD from o ,o_n where FIND_WILD_IN_SET(o.id,o_n.id_o) and o_n.id_n IN ({$start_n_string}) ) M JOIN ( SELECT o.id , o_n.id_n as idA from o,o_n where FIND_WILD_IN_SET(o.id,o_n.id_o) and o_n.id_n IN ({$end_n_string}) ) M2 on M.id = M2.id GROUP by id ) x ); SELECT o.* from o where o.id IN ( select id_offre from o_rv join F on F.id = o_rv.id_offre where find_in_set(idD,o_rv.id_n]) < find_in_set(idA,os_rv.id_n) )"; $list_pot_r=DB::select($query_sql);
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘select o.* from o
NOTE:
- Tried ‘strict’ -> false
- Using DB::select();
- DB::unprepared() the only that doesnt return any error but it doesnt return the result neither only a (TRUE)
EDIT
when i remove the last statment i get this :
SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.
Advertisement
Answer
could be you env don’t allow multiple query in a single statement so due the fact your temp table seems not update try using a dynamic query instead of a create temp table
SELECT o.* from o where o.id IN ( select id_offre from o_rv join (SELECT * from ( select M.* ,M2.idA from ( SELECT o.id , o_n.id_n as idD from o ,o_n where FIND_WILD_IN_SET(o.id,o_n.id_o) and o_n.id_n IN ({$start_n_string}) ) M JOIN ( SELECT o.id , o_n.id_n as idA from o,o_n where FIND_WILD_IN_SET(o.id,o_n.id_o) and o_n.id_n IN ({$end_n_string}) ) M2 on M.id = M2.id GROUP by id ) ) F on F.id = o_rv.id_offre where find_in_set(idD,o_rv.id_n]) < find_in_set(idA,os_rv.id_n) )";