TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Zawodny: Database Abstraction Layers Must Die (at least for PHP)

17 点作者 Shakescode将近 16 年前

12 条评论

Davertron将近 16 年前
I think this is just ridiculous. I'm not necessarily gung-ho about using database abstraction layers myself, but the author only argues against it on the basis of one of the benefits of using an abstraction layer. On top of that, he then admits that he uses a database abstraction layer himself, albeit a seemingly thin one.
评论 #709842 未加载
emilis_info将近 16 年前
Based on my experience, I do not agree with the author.<p>DB Abstraction layer has helped me reuse the same libraries on different DB engines more than once.<p>I had one occurance when I needed to install my new webapp in a hurry (for demonstration purposes) and couldn't arrange for a database with the server administrator fast. Well... I just changed "mysql" to "sqlite" in my DB config, fixed a few problems with SQL CREATE statements and it worked.<p>On a side note I also agree with the "PHP is the best templating languge" idea. I just use a template class for it that has a similar API to Smarty.<p>So yes, I use abstraction layers in both cases. I guess that is more convenient because I do not work on any one web application for too long and I need to carry my libraries and knowledge painlessly from place to place. If I had only one application to build and support at one location... who knows, maybe I would even write php extensions for it in C.
评论 #709989 未加载
nimbix将近 16 年前
I totally agree. DB abstraction libraries buy you very little in terms of database portability. I use them in my projects, but only because their object-oriented APIs are nicer to work with than plain pgsql_<i>/mysql_</i>/etc functions.<p>I worked on at least 3 large projects where we went through a lot of trouble to make them work on multiple databases. All that effort was wasted as all of them ended up running on Postgres only. Unless you're absolutely sure that you're going to need support for multiple databases, my suggestion is that you use the technique from the end of the article: put all of your DB access code in separate classes so you can easily swap them with different ones should the need arise. Until then, save yourself some trouble and make your product work really well with one database engine.
Zak将近 16 年前
<i>So why do folks [make templating systems like Smarty]? Because PHP is also a programming language and they feel the need to "dumb it down" or insulate themselves (or others) from the "complexity" of PHP.</i><p>I don't think that's it, or if it is, it's not a very good reason. Using a templating system that's less than a full programming language keeps you from putting too much logic in your templates. Most of us prefer that logic and presentation be separated. PHP's HTML embedding tempts people to do the Wrong Thing in that regard.
评论 #710218 未加载
abyssknight将近 16 年前
This is bull. I've used straight mysql_* calls, PEAR::MDB2, as well as a custom rolled DB abstraction class before. Personally, I prefered MDB2 because of the portability and ability to do prepared statements (which wasn't available in our version of MySQL and PHP at the time). Changing the few bits of SQL that need changed is far easier than retooling an entire application (i.e. code changes). The other added value is that the developers don't have to relearn the DB functions.
bcl将近 16 年前
Database portability isn't the only reason to use a DB abstraction layer. They provide a way to better integrate the data from the DB with your language's data types and development model. Not to mention making it easier to plug in caching like memcached.<p>If you write your app using an abstraction layer (or even a simple class wrapper), adding caching is almost trivial. If you are using the low level DB function calls it becomes a large task to cache any of your requests.
评论 #710269 未加载
teilo将近 16 年前
I don't know much about PHP abstration layers, but Django's ORM makes an app pretty damn portable from DB to DB. I know, without a doubt, that I could roll out my CMS/blog/documentDB in a heart beat to MySQL, Postgres, Oracle, and SQLite with nothing but a change to the settings file. I have to think that Django is by no means unique in this regard, and that PHP has the equivalent.
评论 #710020 未加载
评论 #709992 未加载
elv将近 16 年前
He starts saying DB abstraction layers are useless and he seem to conclude saying every abstraction and every library not written by you is pointless<p>this seem to me like "I'm paranoid about unknown code but I can't accept the truth SO I reinvent the wheel over and over again putting my code in my library and I say everyone this is cool cause it's faster and performance and bla bla blah"<p>the truth: abstraction -&#62; helps think about the logic that matters in your program library -&#62; helps not to reinvent the wheel and use code tested by everyone<p>his logic: abstraction -&#62; ZOMG unknown stuff HEEELP, let's think about every algorithm in my program from scratch and let's justify this to me by saying I'm saving 3-4 intermediate function calls
IsaacL将近 16 年前
2004! This article is 5 years old, and it's a reply to an article written in 2002!
technomancy将近 16 年前
As long as they take the rest of PHP with them when they die, I'm all for it.
rjurney将近 16 年前
Yeah, put the SQL in the view - where it belongs. Long live Spaghetti PHP!
edw519将近 16 年前
It's tough to take anyone seriously who calls something he disagrees with "bullshit".<p>Database abstraction, like many other things, serves a purpose under the right conditions (when flexibility and portability are needed to serve customers). Get over it.