Jump to content

can't sync from local to server (php_network_getaddresses: getaddrinfo failed: No such host is known)


chokinz

Recommended Posts

<?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);

?>

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.