1

我在我的项目中设置了两个不同的连接:第一个数据库用于新项目,第二个数据库用于获取旧数据并插入新数据库

我的应用程序.ini

; doctrine settings
doctrine.newdsn                = "mysql://user:password@localhost/newdb"
doctrine.olddsn           = "mysql://user:password@localhost/olddb"
doctrine.data_fixtures_path = APPLICATION_PATH "/../doctrine/data/fixtures/data.yml"
doctrine.sql_path           = APPLICATION_PATH "/../doctrine/data/sql"
doctrine.migrations_path    = APPLICATION_PATH "/../doctrine/migrations"
doctrine.yaml_schema_path   = APPLICATION_PATH "/../doctrine/schema"
doctrine.models_path        = APPLICATION_PATH "/models"
doctrine.generate_models_options.generateTableClasses = true
doctrine.generate_models_options.phpDocName = "My Name"
doctrine.generate_models_options.phpDocEmail = "myaddress@email.it"

我的 Bootstrap.php

/**
 * initialize doctrine library
 * @return Doctrine_Connection
 */
protected function _initDoctrine()
{
    // retrieve options
    $doctrine = $this->getOption('doctrine');
    // push doctrine model autoloader
    $this->getApplication()->getAutoloader()->pushAutoloader(array('Doctrine_Core', 'autoload'));
    // push doctrine model autoloader
    $this->getApplication()->getAutoloader()->pushAutoloader(array('Doctrine_Core', 'modelsAutoload'));
    // setup doctrine attributes
    $manager = Doctrine_Manager::getInstance();
    $manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
    $manager->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_CONSERVATIVE);
    $manager->setAttribute(Doctrine_Core::ATTR_AUTOLOAD_TABLE_CLASSES, true);
    $manager->setAttribute(Doctrine_Core::ATTR_QUOTE_IDENTIFIER, true);
    $manager->setAttribute(Doctrine_Core::ATTR_USE_NATIVE_ENUM, true);
    // set default encoding
    $manager->setCharset('utf8');
    $manager->setCollate('utf8_unicode_ci');
    // autoloading models
    Doctrine_Core::loadModels(APPLICATION_PATH . '/models');

    // creating connection
    $connOld = Doctrine_Manager::connection($doctrine['olddsn'], 'olddsn');
    Zend_Registry::set('olddsn', $connOld);
    $connNew = Doctrine_Manager::connection($doctrine['newdsn'], 'newdsn');
    Zend_Registry::set('newdsn', $connNew);

    return $connDoctrine;
}

有了这些配置,就可以轻松地对两个数据库进行读写。我的问题在cli。如果我给出命令 build-all-reload,原则上不是破坏并重新创建新数据库的结构,它也会破坏我的旧数据库,这是我不想要的吗?

我该如何解决?

4

0 回答 0