I would love to know whether this code is the correct manner to send mysql data to a remote database.
$host = 'www.domain.tld';
$user = 'remote_user';
$pass = 'remote_password';
$time_end = microtime(true);
//grant per;misions to connect to remote host
if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
// log in at server1.example.com on port 22
if (!($con = ssh2_connect("www.domain.tld", 22))) {
echo "fail: unable to establish connection\n";
} else {
// try to authenticate with username root, password secretpassword
if (!ssh2_auth_password($con, "remote_user", "remote_password")) {
echo "fail: unable to authenticate\n";
} else {
echo "okay: logged in...\n";
// grant priveliges to access remote database
$priveleges="GRANT ALL ON dest_table.create_info.* TO ' remote_user'@'www.domain.tld'";
//dump database to a file
$dump = "mysqldump -u remote_user -p Profusion.source_cadre > Profusion.source_cadre.sql";
//now compress file for faster upload
$compress="tar zcf Profusion.source_cdr.tar.gz dest_table.sql";
//now start decompressing the file
$decom="tar zxf dumpfilename.tar.gz";
//now import the file to the database
$import="mysql -u remote_user -p dest_table.create_info < Profusion.source_cdr.sql";
//get the number of rows inserted
$progress=mysql_affected_rows();
exec ($priveleges,$dump,$compress,$decom,$import);
sleep(1);
}
I am unable to test this code at the present moment
Your help will be highly appreciated.