1

I was executing sql query in zend something like this and it was working:

$front = Zend_Controller_Front::getInstance();
$bootstrap = $front->getParam('bootstrap');
$resource = $bootstrap->getPluginResource('db');
$dbAdapter = $resource->getDbAdapter();
$statement = $dbAdapter->query("SELECT * from tablename");
$results = $statement->fetchAll();

At that time my application.ini was something like this:

resources.db.adapter = "Mysqli"
resources.db.params.host = "localhost"
resources.db.params.username = "username"
resources.db.params.password = "password"
resources.db.params.dbname = "dbname"

Question:

Now I changed my application.ini to:

resources.multidb.local.adapter = "Mysqli"
resources.multidb.local.host = "localhost"
resources.multidb.local.username = "username"
resources.multidb.local.password = "passwod"
resources.multidb.local.dbname = "dbname"
resources.multidb.local.default = true

Now above zend code is producing following error:

Fatal error: Call to a member function getDbAdapter() on a non-object in Mapper.php  on line 297

How to fix my code according to new application.ini settings ?

Thanks

1

2 Answers 2

1

To retrieve the default Database Adapter use the following code:

$bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
$resource = $bootstrap->getPluginResource('multidb');
$db = $resource->getDb();
Sign up to request clarification or add additional context in comments.

Comments

0

Following code is working for me with multidb configuration in application.ini

$bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
$resource = $bootstrap->getPluginResource('multidb');
$db = $resource->getDb();
$statement = $db->query("SELECT * from tablename");
$results = $statement->fetchAll();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.