Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
358 views
in Technique[技术] by (71.8m points)

jquery - Directly accessing server database via Ajax (without PHP or some other intermediate)

With powerful frameworks like jQuery, it seems to be possible to build an entire app logic on the client side. It's very much analogous to building a client app as a native program.

Now suppose this client app needs to access a remote database. The usual solution seems to involve the layers Ajax/PHP/MySQL.

It seems to me that the PHP layer is no longer needed; all the logic and UI is taken care of by the browser app.

The question then is: Shouldn't there exist a (hopefully robust and secure) database server that simply takes on an HTTP request, and returns an XML result? This result can then be easily parsed by e.g. jQuery on the client side.

I can't seem to find a database or framework along these lines. Any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You mean, is there a database that natively supports the HTTP protocol? Well, there are some. You have MonetDB/XQuery (http://monetdb.cwi.nl/XQuery/QuickTour/XRPC/), and a NoSQL databases like CouchDB (http://couchdb.apache.org/). You also have it in more traditional rdbms-es like Oracle (Oracle Application Express relies on a built-in HTTP server, aka the APEX service http://www.oracle.com/technology/products/database/application_express/index.html) and MS SQL (Service schema object like http://msdn.microsoft.com/en-us/library/ms190332.aspx and XML views, see http://msdn.microsoft.com/en-us/library/aa286527.aspx)

But really - you should question whether this is really that useful.

I mean, there is always going to be one component that handles HTTP. You may have the feeling it is good to take out the webserver/php layer because you feel it is extra, and sits in between the app and the database. But really, the solutions I just mentioned aren't that different - they are tagged on top of the same piece of software, but the data still has to flow through that extra layer.

And you can wonder whether that is really beneficial the have it all in one piece: with a separate webserver, you can scale out the webserver layer independently of the database server. Or you can scale out the database layer independently of the webserver layer. If it's all one piece of software, you can't.

Basically, by building the http server into the database, you're burdening the db server with a task which consumes resources that could have been used for other db tasks. Now think about a common case, where you paid for a per-processor license of your db. Would you really like to spend that license on having the db handle HTTP requests, when you could have done exactly that with a free webserver like apache? Even if you're using a free soft database product, in many cases the database server is a bottleneck. Do you really want to put more tasks on it's plate by building a HTTP server into it?

There's another reason why i think it's not that good an idea. You mentioned XML as data exchange format. Goody. But what if you want JSON? Or YAML? Or perhaps plain CSV? Webserver scripting languages like PHP, ASP.NET, Perl, and even Java all have very good libraries to deal with these things. Typical database stored procedure languages do not. Of course, you can take it a step further and say, hell, why not build say Java or .NET into the database, but that is turning the problem upside down again - the database's task is to store and retrieve data, and take good care of data while it's stored. Processing data to present it to an application is not part of that. If you make it part of the db's job to take care of that, you take away an important source of flexibility and scalability of the system as a whole. You may feel it is less overhead because there's one component less (ie webserver/scripting language) to think about, but in reality, it's still there, it just hides inside your database software, and sucks up the resources that could have been used for storing and retrieving data, parsing queries etc.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...