与 mysqli 相比,使用 Zend_Db 模型有什么优势?
我刚刚开始使用 ZF,有一些非常方便的库可以节省我很多时间,但我看不出使用它们的 Zend_DB 类比 mysqli 有什么优势。我不需要 PDO,因为我将始终使用 MySQL 作为 DBMS。事实上,您在项目中多久更改一次 DBMS?
而且我对 SQL 非常熟悉,所以不需要它们的抽象,这让我很困惑。
那么,与我的类构造函数中的 mysqli 代码然后在需要时仅进行 SQL 查询相比,有什么优势呢?
require_once("database_details.php");
$this->_mysql=new mysqli(DBSERVERHOST,DBUSERNAME,DBPASSWORD,DBNAME);
I've just started using ZF and there's some very handy libraries that save me a lot of time but I can't see the advantage in using their Zend_DB class over mysqli. I don't need PDO as I will always use MySQL as DBMS. And really, how often do you change your DBMS in the middle of a project anyway?
And I'm very comfortable with SQL so don't need their abstraction which just confuses me.
So what advantage is there over this mysqli code in my class constructors and then just SQL queries when I need them?
require_once("database_details.php");
$this->_mysql=new mysqli(DBSERVERHOST,DBUSERNAME,DBPASSWORD,DBNAME);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道 ZF,但裸露的 mysqli 实在是丑陋。获取一些行来填充模板的代码是什么?
让我们假设它和
(这只是手册中的简单示例,没有诸如错误处理之类的强制性内容)
一样令人沮丧,而使用某些库,您可以使其像
只计算常用脚本中的查询数量并感受差异。
另请注意,您的宝贵 SQL 完好无损!
I donno ZF, but bare mysqli is just ugly. What is your code to get some rows to populate a template?
Let's assume it's just as doleful as
(that's just plain example from the manual, with no obligatory things like error handling)
While with some library you can make it like
just count number of queries in your usual script and feel the difference.
Also note that you have your precious SQL intact!
有很多优点。我不知道所有这些,但有两个很突出:
1) 适配器依赖/代码独立
无论您使用什么数据库 - 您的查询代码永远不会改变。
如果您的适配器是 MySQL、PGSQL、MSSQL 等,这并不重要...我认为即使是一些 NoSQL 数据库,Zend 也支持相同的查询格式
2) 缓存
当使用查询库时 - 特别是与 Zend 或 Doctrine(可组合!) - 缓存数据库查询是小菜一碟。为每个查询手动执行此操作,您注定会拥有大量代码:P
3) 可读性
就我个人而言,我只是觉得使用图书馆(也可以是你自己的图书馆)在可读性方面也有很多优势
There are a lot of advantages. I don't know all of them, but two are just outstanding:
1) Adapter Dependency / Code Independency
No matter what Database you use - the code for your Queries NEVER changes.
It doesn't matter if your adapter is MySQL, PGSQL, MSSQL, etc... i think even some NoSQL-Databases are supported with the same query formats by Zend
2) Caching
When using a Library for Queries - especially with Zend or Doctrine (combineable!) - caching your DB Queries is a piece of cake. Do this manually for each of your Queries and you're doomed to have looooots of Code :P
3) Readability
Personally i just feel that using a Library (can be your own one, too) has lots of advantages for readability, too