Symfony: doctrine import sql file



我正在尝试导入 sql 文件(最新版本(但是我找不到正确的语法。

我想执行类似的命令行

PHP bin/console doctrine:query:sql './dump.sql'

提前致谢安德里亚。

如果你想

用symfony命令来做,我想你可以创建你自己的命令,它将文件路径作为参数,然后用PDO执行它。

$file = $input->getArgument('sql');
$sql = file_get_contents($file);
$pdo = $this->entityManager->getConnection()->getWrappedConnection();
$pdo->beginTransaction();
try {
   $statement = $pdo->prepare($sql);
   $statement->execute();
   while ($statement->nextRowset()) {}
   $pdo->commit();
} catch (Exception $e) {
   $pdo->rollBack();
   throw $e;
}

最新更新