[英]Illuminate\Database\QueryException: SQLSTATE[42000]: Syntax error or access violation: 1064
im trying to add this query into my code in laravel.我试图将此查询添加到我在 laravel 中的代码中。 it runs smoothly in phpmyadmin or with mysql command line but enable to get anything but this syntax error.
它在 phpmyadmin 或 mysql 命令行中运行平稳,但除了这个语法错误之外,它可以得到任何东西。
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;
SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select o.* from o
检查与您的 MySQL 服务器版本相对应的手册,以获取在 'select o.* from o 附近使用的正确语法
NOTE:笔记:
EDIT编辑
when i remove the last statment i get this:当我删除最后一条语句时,我得到了这个:
SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active.
SQLSTATE[HY000]:一般错误:2014 在其他无缓冲查询处于活动状态时无法执行查询。 Consider using PDOStatement::fetchAll().
考虑使用 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.
或者,如果您的代码只针对 mysql 运行,您可以通过设置 PDO::MYSQL_ATTR_USE_BUFFERED_QUERY 属性来启用查询缓冲。
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)
)";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.