Being agree with Jeroen that it is better to initialize your db using config file (this lets you changes params in your differentes environments easier), I am not agree that it is the only way of doing it. Reading doc, It is normal become to the conclussion of using _intMyResource() methods in the bootstrap. That is what doc says. What you were doing is right to me except that you are not "returning" any value, and you should do it:
protected function _initDb(){
$params=array('host'=>'localhost',
'username'=>'root',
'password'=>'',
'dbname'=>'mydb');
$db=Zend_Db::factory('PDO_MYSQL',$params);
Zend_Db_Table::setDefaultAdapter($db);
$params=array('host'=>'localhost',
'username'=>'root',
'password'=>'',
'dbname'=>'mydb');
$db=Zend_Db::factory('PDO_MYSQL',$params);
Zend_Db_Table::setDefaultAdapter($db);
return $db;
}
}
that will works!
El 28/08/2009, a las 10:05, Jeroen Keppens escribió:
Hi Neo,If you use resources, you don't need to initialize your db that way. See following url:You add in your app.ini following lines:resources.db.adapter = "PDO_MYSQL"resources.db.params.host = "localhost"resources.db.params.username = "root"resources.db.params.password = ""resources.db.params.dbname = "mydb"You don't have to put anything in your bootstrap.If you want to use the init as specified, you need to make your your boatstrap knows it needs to be loaded.Add something like this to your app.ini :resources.db[] =Specifying this, will make the _initDb to be loaded. However, I would advice using the method explained above if you don't need to do anything special with the db.WkrJeroenOn 28 Aug 2009, at 09:48, neobeacon wrote:
Can anyone help me to set the database adapter form Bootstrap class.
This is my Bootstrap class.
http://www.nabble.com/file/p25185540/Bootstrap.php Bootstrap.php
I used
http://blog.keppens.biz/2009/06/create-modular-application-with-zend.html
keppens's create modular application Tutorial.
I add this code to boot
protected function _initDb(){
$params=array('host'=>'localhost',
'username'=>'root',
'password'=>'',
'dbname'=>'mydb');
$db=Zend_Db::factory('PDO_MYSQL',$params);
Zend_Db_Table::setDefaultAdapter($db);
}
Is this wrong ? What do I want to do?
--
View this message in context: http://www.nabble.com/Setting-Database-Adapter-form-Bootsrap-class-tp25185540p25185540.html
Sent from the Zend MVC mailing list archive at Nabble.com.
没有评论:
发表评论