PHP 使用的哪些数据库共享相同(或大部分)的 SQL 语法?
我读过,虽然 SQL 是为了标准化,但它是用不同的数据库实现的。 我只用过 MySQL 作为数据库。
我想知道其他数据库有哪些共享相同的语法? 我现在正在使用 PDO,我想设置一个标志以允许用户指定他们想要使用哪个数据库。
我有兴趣知道哪些是“安全”数据库,可以处理大多数(如果不是全部)我的常规 MySQL 查询。 主要是SELECT、INSERT、UPDATE、DROP、DELETE。
谢谢
I've read that although SQL is meant to be standardised, it is implemented different etc with different databases. I have only ever used MySQL for databases.
What I would like to know is what other databases share the same syntax? I am using PDO now, and I would like to set a flag to allow the user to specify which database they would like to use.
I would be interested in knowing which are the 'safe' databases that will handle most (if not all) my general MySQL queries. Mainly SELECT, INSERT, UPDATE, DROP, DELETE.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此类称为
ANSI SQL
的版本有多个修订版。理论上,所有主要数据库引擎(即 Oracle、MS SQL、PostgreSQL 和 MySQL)都应该(应该)支持
SQL-92
。这包括您提到的所有内容:
SELECT
、INSERT
、UPDATE
、DROP
、DELETE,只要不使用复杂的子句即可。
实际上:
并非所有数据库都支持全套
SQL-92
。即使在
SQL-92
中编写跨平台SQL
也需要大量测试。当您插入
第 1001 行
行并且需要优化查询时,SQL
中的平台独立性就结束了。如果您浏览一下标记为
SQL
的StackOverflow
问题,您会发现大多数问题都会说“帮助我优化此查询 ”,并且大多数答案都说“使用此依赖于平台的 hack”There are several revisions of a such called
ANSI SQL
.All major database engines (that is
Oracle
,MS SQL
,PostgreSQL
andMySQL
) should (should) in theory supportSQL-92
.This includes everything you've mentioned:
SELECT
,INSERT
,UPDATE
,DROP
,DELETE
, as long as you don't use complex clauses with them.In practice:
Not all databases support the full set of
SQL-92
.Writing cross-platform
SQL
even inSQL-92
requires lots of testing.Platform independency in
SQL
ends when you insert your1001st
row and need to optimize you queries.If you browse a little over
StackOverflow
questions taggedSQL
, you will see that most of them say "help me to optimize this query", and most answers say "use this platform dependent hack"你会发现有些数据库存储数据类型不同,例如mysql将布尔值存储为1和0,而postgres将它们存储为“t”和“f”。
只要您的数据库类意识到需要转换数据,您就应该没问题,可能 96.3482% 的日常 CRUD 都能很好地工作。
即使您创建直接调用 PDO 的数据库类,您也可以稍后添加一些用于数据转换或查询修改的逻辑。
您可以使用数据库抽象层ADOdb。 (它满足了植物的需求)
我建议确保您的客户在花费大量时间开发可能不需要的功能之前,确实关心他们需要运行哪个数据库。
You will find that some database store datatypes differently, for example, mysql stores Booleans as 1 and 0 and postgres stores them as 't' and 'f'.
As long as your database classes are aware of the need to convert data, you should be fine, probably 96.3482% of everyday CRUD will work pretty well across the board.
Even if you create database classes that directly call PDO, you can later on add some logic for data translation or query modification.
You could use the database abstraction layer ADOdb. (its got what plants crave)
I'd suggest making sure that your customers actually give a crap about which database they need to run before you spend a lot of time developing functionality you may not need.
标准化的 SQL92 在所有 RDBMS 中几乎都是相同的。 差异在于标准未定义的部分,例如
LIMIT
或日期时间处理函数,当然还有过程语言。至于 PHP 流行的数据库:让 SQL 在 MySQL、SQLite 和 PostgreSQL 之间移植并不难。 对于 Oracle、Sybase 和 DB/2,事情就没那么容易了。
A standardized SQL92 is pretty much the same in all RDBMS. The differences are in parts, that the standard doesn't define, like for example
LIMIT
or datetime handling functions and of course procedural languages.As for DBs popular with PHP: it not that hard make SQL portable between MySQL, SQLite and PostgreSQL. It won't be that easy with Oracle, Sybase and DB/2.