从另一个站点访问数据 [英] Accessing data from another site

查看:63
本文介绍了从另一个站点访问数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何允许其他网站的PHP从我的网站访问特定数据?

想象一下,我有两个网站,它们托管在同一台服务器上,但是使用各自不同的数据库.但是,我希望网站A能够在其PHP代码中查询和使用网站B数据库的特定信息,而无需了解网站B数据库的结构,表名,字段名等.
例如,B是否可以提供将请求的信息返回给A的功能?

How to allow another websites PHP to access specific data from my site?

Imagine I have two websites, hosted on the same server, but using their own different databases. But, I would like website A to be able to enquire and use in it''s PHP code, specific information from website B''s database, without knowing the structure, table names, field names etc from B''s database.
For instance, could there be functions provided by B that return the requested information to A?

Any suggestions on how to implement something like this?

推荐答案

首先,我想问一下这两个站点是否具有正确的全局体系结构.如果站点是独立的,则可能需要一个站点或两个站点使用 Web服务.

另一个解决方案将缺乏性能和可维护性.如果该站点确实是使用该数据库的网站,则if主要用于生成一些人类可读的 HTTP响应,以响应某些HTTP请求.对人类用户有好处的东西,并未针对某些代码进行优化使用-即使首先已经提供了数据,也需要解析以便再次生成真实数据.正确地来自数据库适配器.

如果-很遗憾-这是您目前唯一的可能性,则需要使用 Web抓取的技术:
http://en.wikipedia.org/wiki/Web_scraping [如何从HTML代码获取信息 [ ^ ].

—SA
First of all, I would question if you have correct global architecture with those two sites. Chances are, you might need to have a Web service used by one site or two sites, if the sites are independent.

The other solution would lack both performance and maintainability. If the site is really a Web site using the database, if is primarily used to generate some human-readable HTTP response in response to some HTTP request. What is good for a human user, is not optimized for the use by some code — you would need to parse the response in order to produce real data again, even though in first place the data was already presented properly when it came from the database adapter.

If — quite unfortunately — this is your only possibility at the moment, you would need to use the techniques of Web scraping:
http://en.wikipedia.org/wiki/Web_scraping[^].

Please see my recent answer:
How to get info from HTML code[^].

—SA


这篇关于从另一个站点访问数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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