Laravel:内连接QueryException

时间:2016-02-09 18:23:19

标签: php mysql laravel laravel-5

我正在尝试在join中的表之间执行Laravel。 但是我在加载页面时收到了这个:

QueryException in Connection.php line 651:

这是查询:

$patches = DB::table('or_patches')
    ->join('or_clients', function($join) use($authid)
    {
        $join->on('or_patches.client_id', '=', 'or_clients.id')
        >where('or_clients.customer_id'. '=', $authid);
    })
    ->get();

如果我删除use()并在静态值上构建“where”,它也不起作用。

详细错误:

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 '1 ?' at line 1 
(SQL: select * from `or_patches` inner join `or_clients` on 
`or_patches`.`client_id` = `or_clients`.`id` and 
`or_clients`.`customer_id=` 1 )

有谁知道为什么?我也试过使用left joins,但没有成功。

更新:尝试更改“。”在where子句中的“,”。这解决了这个问题。谢谢@AlexRussel。

1 个答案:

答案 0 :(得分:1)

从SQL错误的外观(SQL <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div id="other-products"> <input type="checkbox" name="First" value="1"> <input type="checkbox" name="Second" value="2"> <input type="checkbox" name="Third" value="3"> </div> <span class="list-products"></span>的问题)中,您将查询中的...`or_clients.customer_id=` 1附加到字段名称。看一下代码,它看起来就像一个简单的拼写错误,你在方法调用中使用=而不是.,从而将,连接到字段:

=

应该是:

>where('or_clients.customer_id'. '=', $authid);
相关问题