如何从zend mysql DB连接对象访问mysql链接连接资源

发布于 2024-09-29 01:48:55 字数 419 浏览 0 评论 0原文

这是我创建 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仅此而已 2024-10-06 01:48:55

我喜欢通过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

如果您使用Zend Framework 1.8+(并且如果您在application.ini中使用resources.db),您可以通过Zend_Db_Table获取db Adapter的实例到处:

$dbAdapter = Zend_Db_Table::getDefaultAdapter();

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();
甜警司 2024-10-06 01:48:55

不幸的是,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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文