【问题标题】:Symfony Command for MySql Query用于 MySql 查询的 Symfony 命令
【发布时间】:2019-08-12 10:10:43
【问题描述】:

我正在尝试创建一个 Symfony 命令,它在其中运行查询并最终将其作为 cronjob 运行。有人对这个有经验么?到目前为止,这是我的代码。我想知道我应该在哪里创建我的查询。

namespace KCM\GivingBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;





class GivingTranReport extends ContainerAwareCommand
{

    protected function configure()
    {

        $this
            ->setName('giving:report')
            ->setDescriptio('Runs query for giving transactions on hold')
        ;
    }

   protected function execute(InputInterface $input, OutputInterface $output)
   {





   }

【问题讨论】:

  • SO上有大量的DQL示例,你搜索了吗?您的自定义查询应该进入您的实体存储库。至于cron作业,是linux相关的。
  • 对不起,我是教义和symfony的新手。
  • 不用担心,看得出。无论如何,DQL 示例到处都是,搜索一些主题......很难给你一个正确的答案,因为你没有具体说明你想要做什么。所以我们无法真正为您提供 DQL 示例

标签: php mysql symfony doctrine-orm command


【解决方案1】:

执行以下操作:

protected function execute(InputInterface $input, OutputInterface $output)
{
    $connection = $this->getContainer()->get('doctrine')->getConnection();
    $connection->executeUpdate("UPDATE mytable SET mycol = 1 WHERE id = 1");
}

【讨论】:

    猜你喜欢
    • 2021-03-04
    • 1970-01-01
    • 2021-04-29
    • 2016-12-14
    • 1970-01-01
    • 2011-12-10
    • 2019-07-19
    • 1970-01-01
    • 2021-05-05
    相关资源
    最近更新 更多