小编Alf*_*sta的帖子

使用ZF2和Doctrine2将SQL Server表转换为MySQL

我为我的一个客户开发了一个应用程序.他已经有了一个.所以我需要将他的实际数据库(SQL Server)转换为新的数据库(MySQL).

SQL Server的某些表有超过10.000.000条记录.当我开始开发这个转换器时,我已经开始使用一些带有一些记录的表,所以我找到所有记录并保存到我的新MySQL数据库中.我将向您展示一些代码以便更好地理解(这只是一个例子)

<?php

namespace Converter\Model;

class PostConverter extends AbstractConverter 
{

    public function convert() 
    {
        // this is the default connection, it is a mysql database (new application)
        $em = $this->getEntityManager();
        // this return an alternative connection to the sqlserver database (actual application)
        $emAlternative = $this->getEntityManagerAlternative();

        // instance of Converter\Repository\Post
        $repository = $emAlternative->getRepository('Converter\Entity\Post');

        $posts = $repository->findAll();

        foreach ($posts as $post)
            $post = new Post();
            $post->setTitle($object->getTitle());
            $em->persist($post);
        }  

        $em->flush();
    }
}
Run Code Online (Sandbox Code Playgroud)

现在让我们假设Post表有超过10.000.000条记录.我不能只找到所有并迭代它.我会离开RAM.所以我做了这样的事情.

存储库类:

<?php

namespace Converter\Repository;

class Posts extends \Doctrine\ORM\EntityRepository …
Run Code Online (Sandbox Code Playgroud)

php mysql zend-framework doctrine-orm

14
推荐指数
1
解决办法
332
查看次数

标签 统计

doctrine-orm ×1

mysql ×1

php ×1

zend-framework ×1