Zend_Db: Adapter suddenly is null!

邮差的信 提交于 2019-12-11 06:46:38

问题


I'm using Zend_Db in one of my projects. Now I have the problem, that suddenly during the code execution, the variable $_db in Zend_Db_Adapter_Abstract is null. (shown by var_dump($this); in my DbTable_xx class).

It seems like the adapter is set to null somewhere during the script execution. How can that happen?

Unfortunately the project is too complex to post some code here... I'm getting this error (while executing the find($primary) method on Zend_Db_Adapter_Abstract):

Fatal error: Call to a member function quoteTableAs() 
on a non-object in xxx/library/Zend/Db/Table/Abstract.php on line 1162

回答1:


You probably forgot to set the Db adapter for your Zend_Db_Table class.

You can do this in at least three ways:

  • Set an application-wide default for all tables:

    Zend_Db_Table_Abstract::setDefaultAdapter($db);
    
  • Specify the adapter to the table constructor:

    $table = new MyTable( array('db'=>$db) );
    
  • Store the adapter in the registry and specify it to the table or set it as default:

    Zend_Registry::set('my_db', $db); 
    $table = new MyTable( array('db'=>'my_db') );
    // alternatively:
    Zend_Db_Table_Abstract::setDefaultAdapter('my_db');
    

See http://framework.zend.com/manual/en/zend.db.table.html#zend.db.table.constructing




回答2:


Well, that's not too much information. If you want to avoid guessing, I'd suggest to make a copy of the Zend Framework and add some tracer code to those methods that can set $_db using php's built-in debug functions, such as:

  • debug_backtrace()
  • debug_print_backtrace()

to find out what's going on. Afer all, it's open-soure!



来源:https://stackoverflow.com/questions/1491681/zend-db-adapter-suddenly-is-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!