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

 

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();

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

 

 

你可能感兴趣的:(Laravel,问题BUG集锦,MySQL)