views:

250

answers:

3

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?

+1  A: 

I suppose one could do that, but PHP is rather more convenient for manipulating result sets. Also, the traditional approach provides an extra level of security so that machines in the wild don't have direct access to the database, and all the usual webserver security and access controls can be used.

wallyk
+6  A: 

Well, the annoying part is going to be authentication.

Because code is ran completely on the client side, the client then knows all of the authentication details to access the database server.

This is rather .. err ... unsafe. Which is probably why not many people have developed a direct-access server..

If you really want to keep the PHP/Server-Side scripting to a minimum, make a fairly robust PHP proxy than properly escapes all data. Keep the configuration details in a separate protected ini file, or even the php.ini file, and you can pretty much ignore the server-side scripting after that.

Chacha102
I have read and reread this answer, and I keep returning unconvinced...compare it to a mail client and a mail server. Is it inherently unsafe that the mail client knows how to connect to the mailserver, and read a mailbox? Why is that so different from a database account? Of course, you have to apply proper privileges on your database account - something web applications usually don't do - but that doesn't change that you can perfectly secure a databas account like you can with a mail account.
Roland Bouman
@Roland You *could* make every user have a database account. But then each user would have to have their own database too, unless you are able to define privileges by table, in which case each user would need their own table. (Similar to a mailbox)
Chacha102
That's my point Chacha102. In all major rdbms-es you can grant privileges per table. You can even grant them per column. And it doesnt stop with tables and columns, stored routines and views etc can all be granted individually. ANd to manage that some rdbms-es support roles, so you can distribute a package of related privileges. If you really really need to, you can even implement row-level privileges at the database level (using views and/or stored procedures).
Roland Bouman
+4  A: 

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.

Roland Bouman