Zend_Db_Table::getDefaultAdapter is not working_MySQL
程序员文章站
2024-02-13 13:34:37
...
在Bootstrap中使用
$url = constant ( "APPLICATION_PATH" ) . DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR . 'application.ini'; $dbconfig = new Zend_Config_Ini ( $url, "mysql" );// $db = Zend_Db::factory ( $dbconfig->db ); $db = Zend_Db_Table::getDefaultAdapter (); // var_dump ( $db ); $db->query ( "set names utf8" ); // Zend_Db_Table::setDefaultAdapter ( $db );
会出现$db不能实例化的情况,其中Application.ini文件的内容如下:
[mysql]resources.db.adatper=PDO_MYSQLresources.db.isDefaultTableAdapter = trueresources.db.params.host=localhostresources.db.params.username=rootresources.db.params.password=adminresources.db.params.dbname=hsp
在这种情况下需要使用如下方法:
$db = Zend_Db::factory ( 'PDO_MYSQL', array ( 'host' => 'localhost', 'username' => 'root','password' => 'admin', 'dbname' => 'hsp' ) );$db->query ( "set names utf8" );Zend_Db_Table::setDefaultAdapter ( $db );
这种方法可以正确的实例化$db。
推荐阅读
-
Zend_Db_Table::getDefaultAdapter is not working_MySQL
-
Zend Framework教程之Zend_Db_Table表关联实例详解
-
Zend Framework教程之Zend_Db_Table用法详解
-
Zend Framework教程之Zend_Db_Table表关联实例详解_php实例
-
Zend Framework教程之Zend_Db_Table表关联实例详解,zendzend_db_table_PHP教程
-
Zend Framework教程之Zend_Db_Table用法详解
-
Zend_Db_Table返回查询记录集有关问题
-
Zend_Db_Table::getDefaultAdapter is not working_MySQL
-
Zend_Db_Table返回查询记录集有关问题
-
Zend Framework教程之Zend_Db_Table用法详解,zendzend_db_table