简体   繁体   English

从客户端应用程序获取远程数据库信息

[英]Fetching remote database info from a client application

What would be the preferred method of pulling content from a remote database? 从远程数据库提取内容的首选方法是什么?

I don't think that I would want to pull directly from the database for a number of reasons. 我认为出于多种原因,我不希望直接从数据库中提取数据。 (Such as easily being able to change where it is fetching the info from and a current lack of access from outside the server.) (例如,能够轻松更改从中获取信息的位置以及当前从服务器外部无法访问的位置。)

I've been thinking of using HTTP as a proxy to the database basically just using some PHP to display raw text from the database and then grabbing the page and dumping it to a string for displaying. 我一直在考虑使用HTTP作为数据库的代理,基本上只是使用一些PHP从数据库显示原始文本,然后抓取页面并将其转储为字符串以进行显示。

I'm not exactly sure how I would go about doing that though. 我不确定我会怎么做。 (Sockets?) (套接字?)

Right now I am building it around a blog/news type system. 现在,我正在围绕博客/新闻类型系统构建它。 Though the content would expand in the future. 虽然内容将来会扩展。

You might look at using AJAX (I recommend JSON instead of XML though). 您可能会考虑使用AJAX (尽管我建议使用JSON而不是XML)。 This is the technology underlying Google Maps. 这是Google地图的基础技术。

I've got a similar problem at the moment, and the approach I'm taking is to communicate from the client app with a database via a SOAP web service. 目前,我遇到了类似的问题,而我采用的方法是通过SOAP Web服务从客户端应用程序与数据库进行通信。

The beauty of this approach is that on the client side the networking involved consists of a standard HTTP request. 这种方法的优点在于,在客户端,所涉及的网络由标准HTTP请求组成。 Most platforms these days include an API to perform basic HTTP client functions. 目前,大多数平台都包含执行基本HTTP客户端功能的API。 You'll then also need an XML or JSON parser to parse the returned SOAP data, but they're also readily available. 然后,您还需要XML或JSON解析器来解析返回的SOAP数据,但是它们也很容易获得。

As a concrete example, a little about my particular project: It's an iPhone app communicating with an Oracle database. 举一个具体的例子,关于我的特定项目:这是一个与Oracle数据库通信的iPhone应用程序。 I use a web service to read data from the database and send the data to the app formatted in XML using SOAP. 我使用Web服务从数据库读取数据并将数据发送到使用SOAP以XML格式设置的应用程序。 The app can use Apple's NSURLConnection API to perform the necessary HTTP request. 该应用程序可以使用Apple的NSURLConnection API来执行必要的HTTP请求。 The XML is then parsed using the NSXMLParser API. 然后使用NSXMLParser API解析XML。

While the above are pretty iPhone-specific (and are Objective-C based) I think the general message still applies - there's tools out there that will do most of the work for you. 尽管以上内容是特定于iPhone的(并且基于Objective-C),但我认为一般信息仍然适用-那里有可以为您完成大部分工作的工具。 I can't think of an example of an HTTP API offhand, but for the XML parsing part of the equation there's Xerces, TinyXML, Expat... 我想不出一个HTTP API示例,但是对于等式的XML解析部分,有Xerces,TinyXML,Expat ...

HTH! HTH!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM