homepage Welcome to WebmasterWorld Guest from 107.22.45.61
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
Visit PubCon.com
Home / Forums Index / WebmasterWorld / Webmaster General
Forum Library, Charter, Moderators: phranque & physics

Webmaster General Forum

    
Sharing a database across two domains
XML type "EAI" or something cleaner, simpler?
craig1972




msg:338362
 1:51 pm on Aug 21, 2004 (gmt 0)

Hi,

I have two sites, siteA and siteB. With the usual cpanel type hosting, each with a mysql database of course.

Problem is, I need to share one table in either database. Across the two sites.

I can do this in a patchy way by making my own PHP or Perl script that queries the mysql on siteA and then another PHP script on siteB reads that data in because the data is in a certain format (which I can decide).

However, I wonder if there is more intelligent way of doing this through "database replication" or something like that?

Appreciate any thoughts.

Thanks!

 

moltar




msg:338363
 2:10 pm on Aug 21, 2004 (gmt 0)

You can actually query mysql remotely. I know that in later cpanel versions you can specify which IPs are allowed to access the database. So you can do the following:

1) figure out the IP address of your siteA
2) add the above IP into Access Hosts list of siteB database
3) when you conntect to the database, instead of localhost, use IP (or domain) of the siteB.

Sample code ( from cpanel ):

Perl
$dbh = DBI->connect("DBI:mysql:db_name:localhost","db_user","<PASSWORD HERE>");

PHP
$dbh=mysql_connect ("localhost", "db_user", "<PASSWORD HERE>") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("db_name");

craig1972




msg:338364
 2:27 pm on Aug 21, 2004 (gmt 0)

Thanks a bunch moltar, this, if possible, would be the find of the year for me! :)

My concern is that the two sites are on shared hosting so their IP address may in fact be the same. Would that be a problem?

moltar




msg:338365
 2:45 pm on Aug 21, 2004 (gmt 0)

Well, if they are on the same server, then things are much easier... You can just connect to the database like you usually do. You see, databases are not attached to a website, they are independant of the webserver/your account. All you do is just provide correct username and password.

craig1972




msg:338366
 7:29 pm on Aug 21, 2004 (gmt 0)

Shucks, looks like my host has disabled access across the two domain names. It is some server-wide security setting that they're reluctant to alter. Are t hey telling me the truth? Can I suggest something to them to handle this?

A simple php/mysql script on siteB for instance gives me this error:

---
Warning: mysql_connect(): Access denied for user: 'siteA@localhost' (Using password: YES) in /home/siteA/public_html/mysql_test.php on line 12
Could not connect
----

danieljean




msg:338367
 1:41 am on Aug 22, 2004 (gmt 0)

If you can connect to the db from site A, you'll need to use the same username and password when you connect from site B, rather than the one you already use.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / WebmasterWorld / Webmaster General
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved