使用try / catch块使用DB :: statement时如何获取查询绑定

时间:2019-06-16 16:38:32

标签: laravel

使用try / catch块时,如何获取查询绑定?我不确定使用db :: statement时如何执行此操作。这是我目前拥有的,但我也想获取绑定。目前,这只会带回占位符的查询。

DB::transaction(function() use ($decode, $status, $c_decode, $m_decode, $d_decode) {

    try {
        $query = DB::connection('mysql2')->statement('INSERT INTO transactions (json, uuid, status, divisionName, divisionUuid, merchantName, merchantUuid, channelName, channelUuid, channelLogin, channelPwd)
                                                        VALUES (:transaction_1, :uuid, :status_1, :divisionName, :divisionUuid, :merchantName, :merchantUuid, :channelName, :channelUuid, :channelLogin, :channelPwd)
                                                        ON DUPLICATE KEY UPDATE json = :transaction_2, status = :status_2',
                                                        array('transaction_1' => $this->transaction,
                                                            'transaction_2' => $this->transaction,
                                                            'uuid' => $decode->payload->id,
                                                            'status_1' => $status->status,
                                                            'status_2' => $status->status,
                                                            'divisionName' => $d_decode->divisionInfo->name,
                                                            'divisionUuid' => $d_decode->divisionInfo->id,
                                                            'merchantName' => $m_decode->merchantInfo->name,
                                                            'merchantUuid' => $m_decode->merchantInfo->id,
                                                            'channelName' => $c_decode->channelInfo->name,
                                                            'channelUuid' => $c_decode->channelInfo->channel,
                                                            'channelLogin' => $c_decode->channelInfo->login,
                                                            'channelPwd' => $c_decode->channelInfo->pwd));
    }
    catch(Exception $e) {
        Storage::prepend('transactions_insert_errors.txt', Carbon::now('UTC')->toDateTimeString()."\n".$e->getMessage()."\n\n");
    }
}, 3);

0 个答案:

没有答案