通过Ajax直接访问服务器数据库(没有PHP或其他一些中间) [英] Directly accessing server database via Ajax (without PHP or some other intermediate)

查看:146
本文介绍了通过Ajax直接访问服务器数据库(没有PHP或其他一些中间)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过强大的框架,如jQuery的,这似乎是可以在客户端建立一个完整的应用程序逻辑。这是非常类似于建立一个客户端应用程序作为本机程序。

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.

现在假设该客户端应用程序需要访问远程数据库。通常的解决办法似乎涉及层的Ajax / PHP / MySQL的。

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

在我看来,该PHP层不再需要;所有的逻辑和UI是采取由浏览器应用程序的照顾。

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.

接下来的问题是:如果不存在一个(希望稳健和安全)的数据库服务器,仅仅发生在一个HTTP请求,并返回XML结果?这个结果然后可以通过例如很容易地解析jQuery的在客户端

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?

推荐答案

您的意思是,有没有原生支持HTTP协议的数据库?嗯,也有一些。你有MonetDB / XQuery的( http://monetdb.cwi.nl/XQuery/QuickTour/XRPC/ ),而像一个CouchDB的NoSQL数据库( http://couchdb.apache.org/ ) 。你也有它在更传统的RDBMS-ES像甲骨文(Oracle应用防爆preSS依靠内置的HTTP服务器,又名APEX服务的http://www.oracle.com/technology/products/database/application_ex$p$pss/index.html)和MS SQL(如服务模式对象 http://msdn.microsoft.com/en -us /库/ ms190332.aspx 和XML的观点,请参见 HTTP: //msdn.microsoft.com/en-us/library/aa286527.aspx

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.

我的意思是,总有将是一个组件处理HTTP。您可能有它好的取出Web服务器/ PHP层,因为你觉得这是多余的感觉,坐落在应用程序和数据库之间。不过说真的,我刚才提到的解决方案是没有什么不同 - 他们的标签在相同的软件之上,但数据仍然要流过额外的层。

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.

你可以不知道这是否是真正有益的都有了一个段子:有独立的Web服务器,您可以独立于数据库服务器的向外扩展的Web服务器层。或者,您可以独立于Web服务器层向外扩展数据库层。如果这一切都在一个软件上,你不能。

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.

基本上,通过建立HTTP服务器到数据库中,你负担的数据库服务器,这会消耗本来可以用于其他数据库任务的资源的任务。现在想想一个共同的情况下,如果你付出为你的数据库的每个处理器许可证。你真的想花那么牌照上具有数据库处理HTTP请求时,你可能会完全做到这一点有一个免费的网络服务器如Apache?即使你使用的是免费软的数据库产品,在许多情况下,数据库服务器是一个瓶颈。难道你真的想通过建立一个HTTP服务器到它把它的盘子更多的任务?

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?

还有一个原因,我认为这不是好主意。你提到XML作为数据交换格式。好吃的东西。但是,如果你想要的JSON?还是YAML?或许普通的CSV? Web服务器脚本语言如PHP,ASP.NET,Perl和连渣都有着很好的库来处理这些事情。典型的数据库存储过程语言没有。当然,你可以把它更进一步说,地狱,为什么不建说,Java或.NET到数据库中,但毕竟是颠倒再次向下打开的问题 - 数据库的任务是存储和检索数据,并采取良好关心的数据,而它的存储。在处理数据时present它的应用程序是不是其中的一部分。如果你把它分贝的工作就是照顾了一部分,你带走的灵活性,该系统作为一个整体的和可扩展性的重要来源。你可能会觉得这是开销更少,因为有一个分量少(如网络服务器/脚本语言)来思考,但在现实中,它仍然存在,它只是隐藏你的数据库软件中,并吸收了本来可以用于资源存储和检索数据,解析查询等。

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.

这篇关于通过Ajax直接访问服务器数据库(没有PHP或其他一些中间)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆