如何从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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我喜欢通过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:不幸的是,
mysql_connect()
返回的数据库连接与 PDO 适配器不同。请参阅:从 mysql_connect() 获取 PHP PDO 连接?< /a>
也许您可以使用 Mysqli 适配器而不是 PDO MySQL 适配器?
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?