如何从zend mysql DB连接对象访问mysql链接连接资源
这是我创建 zend db 连接的方法
$DB = new Zend_Db_Adapter_Pdo_Mysql(array("host" => "localhost","username" => "root", "password" => "admin123", "dbname" => "user_management"));
我遇到的问题是在我的模型文件中 mysql_query 已用于运行查询。我想将数据库连接从控制器传递到模型。如何直接从 zend db 连接对象获取 php 工厂 mysql 链接资源。
PS:我尝试添加
$db = $DB->getConnection();
这不起作用,我认为这可能是因为缺少一些包含文件。
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.
我喜欢通过application.ini打开连接
如果您使用Zend Framework 1.8+(并且如果您在application.ini中使用
resources.db
),您可以通过Zend_Db_Table获取db Adapter的实例到处:I like to open the connection by application.ini
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: