我对symfony2有疑问。如何在控制器中执行mysql命令?像导入的东西。我尝试使用execute()但没有用(我也没有得到任何错误): mysql -u username --password = password database_name< file.sql
答案 0 :(得分:0)
获取pdo对象:$entityManager->getConnection()->getWrappedConnection()
...
但是沮丧。
否则,在doctrine中,您有一个内置的基于SQL的语言(DQL)来创建类似SQL的请求并返回实体...请参阅doc:http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html
如果你想做一个shell命令,我不明白你为什么要这样做......
答案 1 :(得分:0)
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
$process = new Process('mysql -u username –-password=password database_name < file.sql');
$process->run();
// executes after the command finishes
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
http://symfony.com/doc/current/components/process.html#usage