无法打印原始SQL

时间:2015-05-07 11:08:04

标签: php sql eloquent laravel-5

我尝试了各种选择。我只想获得原始的sql;

$payments = Payment::select('Vendor ZIP')->whereIn('Vendor ZIP', $postcodes)->get()->toArray();

我试过了;

//this
dd(array($payments)); 

//this one
Event::listen('illuminate.query', function($payments)  
    { 
        dd(array($payments));
    });

//this one too
$sql = str_replace(['%', '?'], ['%%', "'%s'"], $payments->toSql());
$fullSql = vsprintf($sql, $payments->getBindings());
print_r($fullSql);

我主要在浏览器上收到No data received错误消息。我还能尝试什么?

顺便说一下,查询是100%正确的。

1 个答案:

答案 0 :(得分:1)

您可以使用toSql方法获取原始SQL查询。

$payments = Payment::select('Vendor ZIP')->whereIn('Vendor ZIP', $postcodes)->toSql();