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

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_34248133/article/details/93478335

laravel 报错,这个报错很长,如下:

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 'concat(path,id) as paths from `web_node` order by `paths` asc' at line 1 (SQL: select ,concat(path,id) as paths from `web_node` order by `paths` asc)

乍一看其实没什么问题,但是我一看代码之后就恍然大悟,原来是我没写要查询的字段,代码如下:

// 结点表数据
$node = Node::select(DB::raw(',concat(path,id) as paths'))->orderBy('paths')->get()->toArray();

看出什么问题了吧,没加要查的字段,加上吧:

// 结点表数据
$node = Node::select(DB::raw('*,concat(path,id) as paths'))->orderBy('paths')->get()->toArray();

这个问题其实不该出现,但是代码调试的时候难免出现这种情况,所以...习以为常!

猜你喜欢

转载自blog.csdn.net/qq_34248133/article/details/93478335
今日推荐