views:

31

answers:

2

Here is how i am creating the zend db connection

$DB = new Zend_Db_Adapter_Pdo_Mysql(array("host" => "localhost","username" => "root", "password" => "admin123", "dbname" => "user_management"));

The problem i have is that in my model files mysql_query have been used to run queries. I want to pass the DB connection from the controller to the model. How do i get the php factory mysql link resource directly from the zend db connection object.

PS: I have tried adding

$db = $DB->getConnection();

This isnt working, I think it maybe because of some include file missing. Can someone help me out with this.

A: 

Unfortunately, mysql_connect() returns a different db connection than the PDO adapter. See:

Getting a PHP PDO connection from a mysql_connect()?

Perhaps you can use the Mysqli adapter rather than the PDO MySQL adapter?

David Weinraub
A: 

I like to open the connection by application.ini

resources.db.adapter = "PDO_MYSQL"
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = ""
resources.db.params.dbname = "dbtest"
resources.db.isDefaultTableAdapter = true

If you're using Zend Framework 1.8+ (and if you use resources.db in application.ini), you can get an instance of db Adapter through Zend_Db_Table everywhere:

$dbAdapter = Zend_Db_Table::getDefaultAdapter();
Jazzo