将多个 dbms 查询响应转换为同一类型的变量 (PHP)

发布于 2024-09-07 14:41:00 字数 296 浏览 1 评论 0原文

我正在制作一个函数(PHP)。在此函数中,它基本上使用指定的 dbms 并连接、提交适当的查询、<在此处插入我的问题>,然后断开连接。 DBMS 包括 MySQL、MSSQL、Postgres 和 Oracle。

我假设在这个函数之外,用户无法访问指定的 DMBS,因此无论我从中得到什么结果,我都需要转换为可用的东西,例如常规 PHP 变量/数组/对象。

我不知道最好的方法来做到这一点(并且只拥有 MySQL 的丰富经验),所以我想知道如何处理每个返回,以便它们都以相对相同的方式出现在 PHP 中。无论如何,我非常感谢一个例子。

I am making a function (PHP). In this function it basically uses the dbms specified and connects, submits the appropriate query, <insert my problem here>, and disconnects. DBMSs include MySQL, MSSQL, Postgres, and Oracle.

I am assuming that outside of this function, the user would not have access to specified DMBS, so whatever results I get from it I need to convert to something usable like a regular PHP variable/array/object.

I don't know the best way to do this (and have only had extended experience with MySQL), so I would like to know how going about handling each return so that they all come out to PHP relatively the same. I would extremely appreciate an example in any case.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

三月梨花 2024-09-14 14:41:00

除非您这样做是为了学习,否则我建议您查看 PDO。它是从 PHP 5 开始内置的,可以处理您提到的 DBMS。

还有 ADODb,它支持更多的 DBMS,但缺点是不是 PHP 的本机编译部分。

在我看来,2010 年不再值得为生产用途编写自己的数据库包装器。周围有太多高质量的行业标准解决方案。

Unless you are doing this to learn, I recommend looking into PDO. It comes built in since PHP 5, and can handle the DBMSs you mention.

There's also ADODb that supports even more DBMSs but has the disadvantage of not being a native, compiled part of PHP.

In my opinion, it's not worth writing an own database wrapper anymore in 2010 for production use. There are too many high-quality industry-standard solutions around.

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