Symfony:在任务中执行自定义 SQL
我基本上想创建一个自定义原则任务来截断所有表中的数据。我通过获取活动的 Doctrine 连接并执行截断表的自定义 SQL 语句来尝试这种方法。当我最终获得连接后,我收到一个致命错误,指出 PDO::execute()
是一个未定义的方法。我需要包含一个文件吗?
代码:
$connection = $databaseManager->getDatabase('doctrine');
$st = $connection->execute("...............");
谢谢
I basically want to create a custom doctrine task that truncates data in all the tables. I was trying this approach by getting the active Doctrine connection, and executing custom SQL statements that truncate the tables. After I finally got the connection, I got a fatal error stating PDO::execute()
is an undefined method. Do I need to include a file?
Code:
$connection = $databaseManager->getDatabase('doctrine');
$st = $connection->execute("...............");
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜您正在寻找 exec。
Guess you were looking for exec.
另一种方法是每次删除数据库:
来源:如何使“symfonydoctrine:build-sql”任务生成“DROP”语句?
Alternative is to the drop the DB each time:
Source: How to make 'symfony doctrine:build-sql' task generate 'DROP' statments?