我正在尝试构建一个脚本,将项目从生产数据库导入到本地数据库,但在将连接形式的生产切换到本地时遇到问题。
Doctrine_Manager::getInstance()->setCurrentConnection('prod-slave');
// execute query to get data from production, confirm it worked
Doctrine_Manager::getInstance()->setCurrentConnection('local');
// insert data into local database
当我运行它时,出现了这个错误:
PHP Fatal error: Uncaught exception 'Doctrine_Connection_Mysql_Exception' with message 'SQLSTATE[HY000]: General error: 1290 The MySQL server is running with the --read-only option so it cannot execute this statement' in...
如果我在将其设置为本地之前关闭与 prod-slave 的连接,我会得到:
PHP Fatal error: Uncaught exception 'Doctrine_Manager_Exception' with message 'Unknown connection: prod-slave' in...
请注意,在这两种情况下,即使我将连接更改为本地,它仍在尝试连接到从站(在第一种情况下,它必须是从站,因为它是只读的)。
我还尝试手动设置连接:
Doctrine_Manager::connection('mysql://path');
Doctrine 版本:1.2.3
Symfony 版本:1.3.9
如有任何帮助,我们将不胜感激。
谢谢
最佳答案
如果您检查为您的模型生成的基类,在一开始您会看到您的每个模型都绑定(bind)到特定的连接。因此,即使您将当前连接设置为另一个连接,也会使用一个绑定(bind)。
解决方案是为每个模型调用 Doctrine_Manager::getInstance()->bindComponent($component, 'local');
。
关于php - 无法更改 Doctrine 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27569200/