使用php脚本将mysql数据输出到csv / txt文件

时间:2015-12-07 10:01:55

标签: php mysql

我正在尝试使用mysql脚本将txt列输出到php - 文件,该查询在mysql上正常工作但在php上失败。单击该按钮时,该函数返回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 个答案:

答案 0 :(得分:1)

你需要逃避你的报价 - 或者更容易..切换到单引号,然后逃避它们(其中少了!)

$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\'';