FuelPHP - 如何执行自定义的多行MySQL语句?

时间:2013-10-24 20:08:59

标签: fuelphp

如何执行执行多个操作的SQL语句?

当我尝试执行以下代码时,出现错误Fuel\Core\Database_Exception [ 1064 ]: You have an error in your SQL syntax;

嵌入了MySQL的PHP​​

$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();

1 个答案:

答案 0 :(得分:2)

此刻你不能。

您可以通过获取当前数据库连接来解决此问题,并直接使用本机PHP调用

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

Afaik本机MySQL驱动程序根本不支持多个语句。