chokinz Posted January 9, 2014 Share Posted January 9, 2014 <?php $db_local_host = 'localhost'; $db_local_user = 'root'; $db_local_password = ''; $db_local_db = 'my_localdb'; $db_local_table = 'my_maintable'; $db_remote_host = 'http://www.mydomain.net/'; $db_remote_user = 'mydomain_admin'; $db_remote_password = 'mydomain_passwd'; $db_remote_db = mydomain_db'; $db_remote_table = 'my_maintable'; $dump = shell_exec("mysqldump -u{$db_local_user} -p{$db_local_password} --no-create-info --compact {$db_local_db} {$db_local_table}"); echo "Connecting to remote db...\n"; $link = mysql_connect($db_remote_host, $db_remote_user, $db_remote_password); if (!$link) { die('Could not connect to remote db: ' . mysql_error()); } echo "Connected successfully\n"; if (!mysql_select_db($db_remote_db, $link)) { die ("Can't connect to db {$db_remote_db}" . mysql_error()); } echo "Connected to db {$db_remote_db}\n"; $sql = "TRUNCATE TABLE {$db_remote_table}"; echo "Running query: {$sql}\n"; $res = mysql_query($sql) OR die(mysql_error()); echo $res ? "success\n": "failed\n"; echo "Running dump query\n"; $dump = str_replace("INSERT INTO `{$db_local_table}` ", "INSERT INTO `{$db_remote_table}` ", $dump); $dumps = explode("\n", $dump); $res = null; foreach ($dumps as $dump) { $dump = trim($dump); if($dump){ $res = mysql_query($dump) OR die(mysql_error()); } } $res = mysql_query($dump) OR die(mysql_error()); echo $res ? "success\n": "failed\n"; mysql_close($link); ?> Quote Link to comment Share on other sites More sharing options...
chokinz Posted January 9, 2014 Author Share Posted January 9, 2014 btw, i'm using win8 64bit w/ xampp 1.8.1 Quote Link to comment Share on other sites More sharing options...
kicken Posted January 9, 2014 Share Posted January 9, 2014 (edited) $db_remote_host should be just a hostname, not a URL. Edited January 9, 2014 by kicken Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.