PHP SQL Query building engine

发布于 2022-09-06 12:35:52 字数 2468 浏览 24 评论 0

I'm looking for query building engine for PHP (not ORM!) which would satisfy some criteria specified below. Unfortunately, after looking into Doctrine, Propel, Adodb, Zend_Db, etc. I couldn't find any that really fits the profile - they are either too abstract (I don't need ORM-level abstraction) or don't support enough features. What I need is a library that would allow me to build the SQL query programmatically - I don't even need it to run it, though that would be OK too.

I really would like to avoid reinventing the wheel, so if you know something that fits the profile please bring it forward. If you think one of those named above fits (and I missed that), please tell me too.

MUST HAVE (if library doesn't have it, it's not useful for me):

  • Support PHP 5.2 (namespaced libraries can't be used for now, unfortunately)
  • Support programmatic query generation, including select expressions, order-by, limit, group-by, having, unions, outer joins, etc.
  • Support Mysql, Oracle oci8, MSSQL, DB2, Postrges
  • Support building named parametrized queries & prepared statements
  • Support adding conditions/joins dynamically at any point
  • Support for datatypes like datetime, etc. - e.g., properly formatting incoming/outgoing data, use proper comparison functions if needed, etc. (and of course proper quoting). We know types of all the fields in the code, so the library should allow us to tell it what each field is.
  • Stand-alone (easy to use without tons of other support classes)
  • Easy to extend and license allows extending on BSD-like terms
  • Clean PHP 5 code (no PHP 4 object-by-ref cruft, etc.)

NICE TO HAVE (we could implement that on top of "must have"s but would be happier if it were already done)

  • Support instantiating parametrized queries (full & partial) - i.e. after having built a query support giving it part of the params and generate new query with those params substituted
  • Support merging two queries (i.e. adding conditions and tables from one query into another)
  • Support query comments (including parametrizing them)

BONUS (this would really make us happy, but we could live without it for now)

  • Support serialization
  • Support caching

So, does anyone know such library?

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

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

发布评论

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

评论(1

迷路的信 2022-09-13 12:35:52

CodeIgniter is a safe bet for what you're looking for: http://codeigniter.com/user_guide/database/active_record.html

Also, it can easily be extended from it's core to do what you need. It also has query caching (one of your bonus items).

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