Laravel 4: how get failing INSERT query SQL with insert

147 Views Asked by At

I need to work on a legacy product with Laravel 4 (and I cannot update it).

I need to read the real query executed but I cannot get it.

This is my model:

class MigrationData {
    
    protected $log = "";
    
    public function executeMigration($id, $own, $company_id = null)
    {
        DB::transaction(function($conn) use($id, $own, $company_id) {
            DB::connection('connection_01')->transaction(function($conn) use($id, $own, $company_id) {
            // stuffes
            $customer = new Customer();
            try {
                 $customer->save();
                 Log::debug(DB::connection('connection_01')->getQueryLog());
            } catch (Exception $e) {
                 Log::debug(DB::connection('connection_01')->getQueryLog());
            }
            exit();
        })->enableQueryLog();
    })
}

I can log other queries, but not the insert (the INSERT itself returns an error of Oracle Database but I would track exact query).

Thank you

1

There are 1 best solutions below

0
Onur Uslu On

The transaction method doesn't return an instance of its class. Let me give an example:

$response = DB::transaction(function(){

    // ... (Some DB operations)

    return 'Hello World';
});

// It prints "Hello World."
echo $response;

Therefore, you cannot make method chaining. Try to separate it like below:

DB::enableQueryLog()

DB::transaction(...);