vendredi 6 janvier 2017

Laravel / Eloquent - How Do You Run Multiple Raw SQL Statements At the Same Time?

I have multiple SQL statements I'd like to run through Eloquent. They look something like this:

CREATE TEMPORARY TABLE cars
    AS (SELECT cars.id, cars.ip_address
        FROM cars
            JOIN colors ON colors.ip_address = cars.ip_address);

CREATE TEMPORARY TABLE boats
    AS (SELECT ip_address, MIN(id) AS id
        FROM colors
        GROUP BY ip_address);

CREATE TEMPORARY TABLE rvs
    AS (SELECT rvs.id, rvs.ip_address
        FROM rvs
            LEFT JOIN colors ON colors.id = rvs.id
        WHERE colors.id IS NULL);

/* Do things with temp tables here */

I need all of these statements to run in one connection session since they are using temporary tables. I've tried using DB::statement() which errors out at the start of the second statement operation and also DB::unprepared() which doesn't seem to run any of the operations.

Is there a way to run multiple raw statements using Eloquent?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2hYibrM
via IFTTT

Aucun commentaire:

Enregistrer un commentaire