Home > Database > Mysql Tutorial > Zend_Db_Table::getDefaultAdapter is not working_MySQL

Zend_Db_Table::getDefaultAdapter is not working_MySQL

WBOY
Release: 2016-06-01 13:08:04
Original
796 people have browsed it

在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 );
Copy after login

会出现$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
Copy after login

在这种情况下需要使用如下方法:

$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 );
Copy after login

这种方法可以正确的实例化$db。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template