Laravel:print_r查询输出时允许的内存大小耗尽

时间:2018-02-27 10:54:05

标签: php mysql laravel

我已经阅读了数十个报告此问题的问题,而且在所有这些问题中,最佳答案是"增加memory_limit"。很公平,但在这里我有一个memory_limit=128M,我试图检索两个行,所以我猜在查询中有错误。

这是LampsController@create中的代码:

$families = DB::table('families AS f')
    ->join('products_families AS pf', 'pf.family_id', '=', 'f.id')
    ->join('products AS p', 'pf.product_id', '=', 'p.id')
    ->select(DB::raw('f.code'))
    ->where('p.category', '=', 'lamps');
// $families = Collection::unwrap($families);
print_r($families); exit;

数据库架构很简单:

A)表families

----------------------------------------------
| id | code | name | created_at | updated_at |
|    |      |      |            |            |
----------------------------------------------

B)表products_families

---------------------------------------------------------
| id | product_id | family_id | created_at | updated_at |
|    |            |           |            |            |
---------------------------------------------------------

C)表products

-------------------------------------------
| id | category | created_at | updated_at |
|    |          |            |            |
-------------------------------------------

这是我得到的错误:

Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN)
Allowed memory size of 134217728 bytes exhausted (tried to allocate 98570240 bytes)

我做错了什么?

1 个答案:

答案 0 :(得分:4)

添加get()以获取查询结果,如果要打印查询,可以使用toSql()