Question

How do I execute an SQL statement that is performing multiple actions?

When I try to execute the following code, I get an error Fuel\Core\Database_Exception [ 1064 ]: You have an error in your SQL syntax;

PHP with MySQL embeded

$sql = "
    SET @sql = CONCAT(
        'CREATE TEMPORARY TABLE IF NOT EXISTS temp_compiled_properties AS
        (SELECT
            id, 
            ', @sql, '
        FROM properties
        WHERE properties.property_id = ?
        GROUP BY properties.property_id)');

    PREPARE stmt FROM @sql;
    EXECUTE stmt USING @property_id;
    DEALLOCATE PREPARE stmt;";  

    DB::query($sql)->execute();
Was it helpful?

Solution

At the moment you can't.

You can work around it by fetching the current database connection, and use the native PHP calls directly

$db = \DB::instance()->connection();
$result = $db->exec($sql); // for PDO

Afaik the native MySQL drivers don't support multiple statements at all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top