Reputation: 69
I am trying to output mysql
columns to txt
-file using php
script, the query works fine on mysql
but fails on php
. When clicked on the button the function returns Internal Server error
.
function RsyncFTPAction() {
$sql = "SELECT CONCAT("sshpass -p ""Password"" rsync -avvtzh -e ""ssh -o StrictHostKeyChecking=no"" --log-file=""/home/toor/rsync2.log""", login,"@", ftp_addr, " :", camera_name,"/", "/",'home',"/",login, "/", camera_name)
FROM inteliviz.cameras order by id INTO OUTFILE '/tmp/wptitles2.csv' LINES TERMINATED BY '\r\n'";
$result = $conn->Execute($sql);
if(!$result) {
print $conn -> ErrorMsg(); ;
exit;
}
}
Upvotes: 0
Views: 90
Reputation: 3337
You need to escape your quotes - or easier.. switch to single quotes, and escape them (there's less of them!)
$sql = 'SELECT CONCAT("sshpass -p ""Password"" rsync -avvtzh -e ""ssh -o StrictHostKeyChecking=no"" --log-file=""/home/toor/rsync2.log""", login,"@", ftp_addr, " :", camera_name,"/", "/",`'home`',"/",login, "/", camera_name)
FROM inteliviz.cameras order by id INTO OUTFILE \'/tmp/wptitles2.csv\' LINES TERMINATED BY \'\r\n\'';
Upvotes: 1