0

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

1 Answer 1

1

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\'';
Sign up to request clarification or add additional context in comments.

4 Comments

I can't see, that you escaped the quotes
..The single quotes are escaped, rather than the double ones.
This will still end up in a parse error. For example here: ,'home
Ah yes, Missed one, I gave him the correct answer though, not all SO is meant to be copy and paste :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.