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

?>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.