Dump database data using Doctrine 2

后端 未结 6 2173
萌比男神i
萌比男神i 2021-01-01 21:50

Is it possible to dump a database using doctrine 2? I have read that symfony has a library which extends doctrine to do it but How could I use it in my zendframework project

6条回答
  •  无人及你
    2021-01-01 22:16

    For a more generic doctrine way:

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $conn = $this->getDoctrineConnection('default');
    
        $path = $input->getArgument('filepath');
        if (! is_dir(dirname($path))) {
            $fs = new Filesystem();
            $fs->mkdir(dirname($path));
        }
    
        $cmd = sprintf('mysqldump -u %s --password=%s %s %s > %s',
            $conn->getUsername(),
            $conn->getPassword(),
            $conn->getDatabase(),
            implode(' ', ['variables', 'config']),
            $path
        );
    
        exec($cmd, $output, $exit_status);
    }
    

提交回复
热议问题