MySQL 通过 ADOdb PHP 到 DB2

发布于 2024-11-02 04:50:05 字数 201 浏览 0 评论 0原文

我正在尝试将一个小型 PHP 应用程序从 MySQL 移植到 DB2。该应用程序通过 ADOdb 连接到 MySQL 数据库。我成功地通过 ADOdb 连接到 DB2 数据库,但执行 SQL 查询却不太成功。需要修改查询以在要执行的表名称周围包含引号 (" ")。他们在 ADOdb 中有解决方法吗?修改每个查询有点乏味(这实际上违背了使用 ADOdb 的初衷)。

谢谢!

I'm trying to port a small PHP application to DB2 from MySQL. The application connects to a MySQL database through ADOdb. I was successful in connection to the DB2 database through ADOdb, but I wasn't so successful in executing the SQL queries. The queries needed to be modified to include quotation (" ") marks around table names to execute. Is their any workaround in ADOdb for this? It's a bit tedious to modify each query (which actually defeats the purpose of using ADOdb in the first place).

Thanks!

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

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

发布评论

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

评论(2

满天都是小星星 2024-11-09 04:50:05

在 DB2 中,默认情况下,模式、表和列名称不区分大小写。当您发出语句时:

create table myid.test (
   c1 int
   c2 int
);

DB2 将模式、表和列名称折叠为大写。因此,如果您查看系统目录,您将看到该表名为 MYID.TEST 并且具有列 C1 和 C2。

DB2 也将所有查询折叠为大写(默认情况下)。因此,当您查询此表时,以下语句是相同的:

select c1, c2 from myid.test

SELECT C1, c2 from MYID.TEST

SELECT c1,来自 MyID.Test 的 C2

然而,DB2可以使用区分大小写的名称:如果您在定义中引用架构/表/列名称,那么 DB2 将使用确切的字符串:

   create table "MyID"."Test" (
      c1 int,
      "C2" int
   );

在本例中,你会看到系统目录中混合大小写的架构/表/列名称。

这会产生不幸(且痛苦)的副作用,即要求您在所有查询、DML 和 DDL 中引用架构/表/列名称。

使用混合大小写名称不是最佳实践。

最好的解决方案是重新创建不区分大小写的名称的表(即不要将架构/表/列名称放在引号中。

这将消除使用 ADODB 覆盖所有内容的需要 ADODB 可能有一些解决方法,但对其他人来说仍然存在痛苦。

In DB2, by default, schema, table and column names are not case sensitive. When you issue the statement:

create table myid.test (
   c1 int
   c2 int
);

DB2 folds the schema, table and column names into upper case. Therefore, if you look in the system catalog, you'll see that the table is called MYID.TEST and has columns C1 and C2.

DB2 folds all queries into upper case as well (by default). So, when you query this table, the following statements are identical:

select c1, c2 from myid.test

SELECT C1, c2 from MYID.TEST

SELECT c1, C2 from MyID.Test

However, DB2 can use case sensitive names: If you quote the schema/table/column names in the definition, then DB2 will use the exact strings:

   create table "MyID"."Test" (
      c1 int,
      "C2" int
   );

In this case, you'll see the mixed case schema/table/column names in the system catalog.

This has the unfortunate (and painful) side effect of REQUIRING that you quote your schema/table/column names in all of your queries, DML and DDL.

Using mixed case names is NOT best practice.

The best solution would be to re-create your tables without the case-sensitive names (i.e. don't put schema/table/column names in quotes.

This will eliminate your need to override everything with ADODB. It's possible that there is some workaround for ADODB, but the pain will still exist for anyone else.

羁拥 2024-11-09 04:50:05

每一个都要修改,有点繁琐
查询(这实际上击败了
首先使用ADOdb的目的
地点)。

虽然这可能很乏味,但您必须这样做。 JDBC 在 Java 中提供了等效的功能,并且您必须编写特定于您的特定数据库的 SQL。这就是数据库开发的工作原理。除非您使用 Hibernate(一种 Java ORM)之类的某种抽象层来向您隐藏 SQL 的细节,否则您必须调整它以在不同的数据库上运行。

很高兴到目前为止您遇到的唯一事情就是添加一些引号。当将复杂查询从一台服务器转换到另一台服务器时,人们常常不得不重写大部分查询。

It's a bit tedious to modify each
query (which actually defeats the
purpose of using ADOdb in the first
place).

While it certainly may be tedious, you'll have to do it. JDBC provides the equivalent functionality in Java, and there you have to write SQL that is specific to your particular database. This is just how it works with database development. Unless you use some sort of abstraction layer like Hibernate (a Java ORM) to hide the specifics of the SQL from you, you'll have to tweak it to run on a different database.

Be glad that the only thing you've encountered so far is adding a few quotation marks. People frequently end up having to rewrite most of the query when converting a complex query from one server to another.

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