Calling table from external database/cms install

8 posts by 4 authors in: Forums > CMS Builder
Last Post: April 23, 2010   (RSS)

By rjbathgate - June 11, 2009 - edited: June 11, 2009

Hey,

I have a CMS install on:

www.example.com

and another on:

www.exampletwo.com

On exampletwo.com, I have a news table, and a news listing page, working fine.

On example.com, I want to be able to create a news listing page, which pulls the data from exampletwo.com's news table.

I thought I should be able to do this by, in example.com/news.php simply loading the external path to exampletwo's CMS:
require_once "http://www.exampletwo.com/cmsAdmin/lib/viewer_functions.php";

However, this doens't work!!

I get the following error when trying to load example.com/news.php (with the call to the exampletwo.com cms:


Warning: require_once(): URL file-access is disabled in the server configuration in http://www.example.com/news.php on line 14 Warning: require_once(http://www.exampletwo.com/cmsAdmin/lib/viewer_functions.php): failed to open stream: no suitable wrapper could be found in http://www.example.com/news.php on line 14 Fatal error: require_once(): Failed opening required 'http://www.exampletwo.com/cmsAdmin/lib/viewer_functions.php' (include_path='http://www.example.com/cmsAdmin:.:/usr/lib/php:/usr/local/lib/php') in http://www.example.com/news.php on line 14


The two sites/cms installs are on the same fixed IP server (i've just used example and exampletwo for illustration here).

Is there something else I need to do to get example.com to be able to pull exampletwo.com's database? (in addition to its own database).

Cheers
Rob

Re: [Dave] Calling table from external database/cms install

By rjbathgate - June 11, 2009

Hey,

Thanks - used getPage -- had to tweak a few things to compensate for page being external, but got there in the end, cheers!

Rob

Re: [rjbathgate] Calling table from external database/cms install

By kdub718 - April 13, 2010

I'm trying to do this same thing...

I just can't get it to work. Can you maybe explain how you used the getPage function? Do you have to replace the require_once?

Lets say I have siteA and siteB...

I want siteA to have the mysql database and then have siteB pull the same (for example) newspage as siteA.

Re: [kdub718] Calling table from external database/cms install

Ok,

You need a php page displaying the news articles form your sql, so on siteA.

Say: www.sitea.com/news-for-siteb.php

This file renders the news as required as you would if it was a news page for siteA. Completely normal.

Then on siteB you have www.siteb.com/news-from-sitea.php, and within it, where you want the news to display, the code:

<?php
list($html, $httpStatusCode) = getPage("http://www.sitea.com/news-for-siteb.php");
print $html;
?>


So this essentially displays the contents of news-for-siteb.php from SiteA (rendered by siteA).

Your require_once stuff is on www.sitea.com/news-for-siteb.php as if it were a normal news page for siteA.

For styling, I would recommend having www.sitea.com/news-for-siteb.php include your layout requirement (<divs> etc), with siteB having the css for said <divs>

Hope this helps

Re: [rjbathgate] Calling table from external database/cms install

By Chris - April 14, 2010

Hi there,

Just a note: many hosts will allow you to host multiple web sites (e.g. www.sitea.com and www.siteb.com) both from the same server. This configuration may simplify things greatly. :)
All the best,
Chris

Re: [chris] Calling table from external database/cms install

By kdub718 - April 16, 2010 - edited: April 16, 2010

But I think both domain names would have to be on that server aswell. Which in this case they are not.

I mean you can forward but then essentially your leaving that domain and if people bookmark its kinda dumb. Among many other reasons...

Then blind forward will always take you back to index page if you refresh or anything like that.

maybe I'm wrong and there is another way...?

Re: [kdub718] Calling table from external database/cms install

By Dave - April 23, 2010

>maybe I'm wrong and there is another way...?

You can do a redirect with mod_rewrite like this that will maintain the path from root and the query string, etc:

# Redirect to new domain
RewriteEngine on
RewriteRule ^(.*)$ http://www.example.com/$1 [L,QSA]

http://www.siteA.com/dir/file.php?name=value#link redirects to:
http://www.example.com/dir/file.php?name=value#link

Or if you have mod_rewrite and mod_proxy you can do this:

RewriteEngine on
RewriteRule ^(.*)$ http://www.example.com/$1 [P,QSA,L]

http://www.siteA.com/dir/file.php?name=value#link loads the content from
http://www.example.com/dir/file.php?name=value#link

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com