简体   繁体   English

Laravel中的MySQL Access冲突可在phpmyadmin中使用

[英]MySQL Access violation in Laravel that works in phpmyadmin

I've just started using Laravel Framework and found a nice little guide for hierarchical-data (through this site) that I have working quite well. 我刚刚开始使用Laravel Framework,并找到了一个很好的有关层次结构数据的小指南(通过此站点),我工作得很好。

The only problem I've come across is running the following code through Laravel: 我遇到的唯一问题是通过Laravel运行以下代码:

DB::query("LOCK TABLE pages WRITE;
        SELECT @myLeft := lft FROM pages WHERE id = ?;
        UPDATE pages SET rgt = rgt + 2 WHERE rgt > @myLeft;
        UPDATE pages SET lft = lft + 2 WHERE lft > @myLeft;
        UNLOCK TABLES;", 1);

Works fine when I run the command through phpmyadmin but in Laravel I get an error: 通过phpmyadmin运行命令时工作正常,但在Laravel中出现错误:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax;

I have many other queries running fine, so I don't know where to begin looking, I've already tried adding ` to the table and field names, and removed the locks to see if that would do anything but no change. 我还有许多其他查询运行良好,所以我不知道从哪里开始寻找,我已经尝试过在表名和字段名中添加`,并删除了锁以查看是否可以进行任何操作,但是没有任何变化。

ok I'm thinking Lavarel its wanting to run a single query and I'm trying to run five, when I split the command as below it works, 好的,我认为Lavarel想要运行一个查询,而我尝试运行五个,当我按如下所示拆分命令时,

$ord = DB::first("SELECT lft FROM pages WHERE id = ?;", $order);            
        DB::query("UPDATE pages SET rgt = rgt + 2 WHERE rgt > ?;", $ord->lft);
        DB::query("UPDATE pages SET lft = lft + 2 WHERE lft > ?;", $ord->lft);

Do only one query per DB::query() . 每个DB::query()仅执行一个查询。 Without looking at the source, this method is designed to run only one statement. 无需查看源代码,此方法仅设计为仅运行一条语句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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