开发者

how to access mysql link connection resource from zend mysql DB connection object

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_q开发者_如何学Pythonuery 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.


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();


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜