jonas-e
11-01-2007, 02:32 PM
I want to make a script that transfers my local database to my remote web host - I have come as far as making a dump file of my local db and upload it using ftp to the web host:
$d="C:/xampp/mysql/bin/mysqldump --skip-opt --insert-ignore --add-drop-table --host=*** --user=*** --password=*** db_name > dump.sql";
exec($d);
// set up basic connection
$ftp_server="ftp.***.no";
$conn_id = ftp_connect($ftp_server);
// login with username and password
$ftp_user_name="***";
$login_result = ftp_login($conn_id, $ftp_user_name, '***');
// turn passive mode on
ftp_pasv($conn_id, true);
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!<br />";
echo "Attempted to connect to $ftp_server for user $ftp_user_name<br />";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name<br />";
}
$destination_file="dump.sql";
$source_file="dump.sql";
// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
// check upload status
if (!$upload) {
echo "FTP upload has failed!<br />";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file<br />";
}
// close the FTP stream
ftp_close($conn_id);
That works great!
Then I try to execute the dump file on the remote web host like this:
$myFile = "dump.sql";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
if (!mysql_query($theData)) {
echo mysql_error();
} else {
echo "SUCCES!<br />";
}
And I get the following error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101' at line 7
If I paste the dump.sql file (located here http://skred-svalbard.no/dump.sql) into a mysql command or phpadmin - it works just fine! But when I pass it through the mysql_query, I get error messages.
Can anyone see what the error is?
Am I perhaps just using an entirely wrong php command "mysql_query"?
cheers, j
$d="C:/xampp/mysql/bin/mysqldump --skip-opt --insert-ignore --add-drop-table --host=*** --user=*** --password=*** db_name > dump.sql";
exec($d);
// set up basic connection
$ftp_server="ftp.***.no";
$conn_id = ftp_connect($ftp_server);
// login with username and password
$ftp_user_name="***";
$login_result = ftp_login($conn_id, $ftp_user_name, '***');
// turn passive mode on
ftp_pasv($conn_id, true);
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!<br />";
echo "Attempted to connect to $ftp_server for user $ftp_user_name<br />";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name<br />";
}
$destination_file="dump.sql";
$source_file="dump.sql";
// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
// check upload status
if (!$upload) {
echo "FTP upload has failed!<br />";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file<br />";
}
// close the FTP stream
ftp_close($conn_id);
That works great!
Then I try to execute the dump file on the remote web host like this:
$myFile = "dump.sql";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
if (!mysql_query($theData)) {
echo mysql_error();
} else {
echo "SUCCES!<br />";
}
And I get the following error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101' at line 7
If I paste the dump.sql file (located here http://skred-svalbard.no/dump.sql) into a mysql command or phpadmin - it works just fine! But when I pass it through the mysql_query, I get error messages.
Can anyone see what the error is?
Am I perhaps just using an entirely wrong php command "mysql_query"?
cheers, j