Welcome to WebmasterWorld Guest from 126.96.36.199
Forum Moderators: phranque
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.
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 ):
$dbh = DBI->connect("DBI:mysql:db_name:localhost","db_user","<PASSWORD HERE>");
$dbh=mysql_connect ("localhost", "db_user", "<PASSWORD HERE>") or die ('I cannot connect to the database because: ' . mysql_error());
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