I have two servers hosting two different sites with two separate databases. However, some of the data needs to be shared - so there's a CRON that runs to copy that data from the first site to the second site. These two sites used to run on the same server, but now we have separated them so I'm attempting to amend the PHP to be able to handle this.
Here is the code where I'm encountering the problem:
$sql = "SELECT * FROM site1.events";
$events = mysql_query($sql, $site1db);
$sql = "INSERT INTO site2.events SELECT * FROM $events";
$doIt = mysql_query($sql, $site2db);
Now I know that the SELECT * FROM site1.events is successful, but it cannot insert into the second site and I'm not seeing any sort of error. I've never written PHP before (this is a legacy task) so if it's something that's been covered before - do point me in the right direction.
Please note that site2.events is truncated before these commands so no compare is necessary.
mysqliinstead ofmysql. Not too sure how it handles mutliple servers but you could have a look at Federated tables.$eventsis a mysql resource and I don't think you can use it as a string, however you can write ` * FROM ($sql)` since$sqlis a string. Please notice that you're usingmysql_which is deprecated and consider usingmysqli_as @Coloco suggested orPDO.