0
    $a = '
        SELECT * FROM `'. $table .'` WHERE `chrDate` > "'. $lastDate .'" INTO OUTFILE "'. $file .'"
        FIELDS TERMINATED BY ", " ENCLOSED BY \'"\' ESCAPED BY "\"
        LINES TERMINATED BY "\n"
';

我不知道为什么我不能这样做,我尝试解决了好几次但每次我都给出这个错误:(

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 '\n"' at line 2

*回声$a *

SELECT * FROM `tbl_SaleApa` WHERE `chrDate` > "2001/03/29" INTO OUTFILE "C:/xampp/htdocs/transfer/tempfile/tbl_SaleApa.sql"
FIELDS TERMINATED BY ", " ENCLOSED BY '"' ESCAPED BY "\"
LINES TERMINATED BY "\n"
4

4 回答 4

1

我有这个: 编辑:您还将变量封装在不需要的双引号中。请参阅更新的代码。

<?php

$table='myTable';
$lastDate='myDate';
$file='myFile.ext';
$a = "SELECT * FROM $table WHERE chrDate > '$lastDate' INTO OUTFILE '$file' 
    FIELDS TERMINATED BY ', ' ENCLOSED BY '\"' ESCAPED BY '\\' 
    LINES TERMINATED BY '\\n'"; 

echo $a;

?>

哪个输出:

SELECT * FROM myTable WHERE chrDate > 'myDate' INTO OUTFILE 'myFile.ext'
FIELDS TERMINATED BY ', ' ENCLOSED BY '"' ESCAPED BY '\' 
LINES TERMINATED BY '\n'
于 2012-08-08T09:09:23.197 回答
0

我的问题解决了:

$a = '
SELECT * FROM `'. $table .'` WHERE `chrDate` > "'. $lastDate .'" INTO OUTFILE "'. $file .'"
FIELDS TERMINATED BY ", " ENCLOSED BY \'"\' ESCAPED BY "\\\"
LINES TERMINATED BY "\n"
';

更改ESCAPED BY "\"ESCAPED BY "\\\"

于 2012-08-08T09:33:27.123 回答
0
$sql = '
SELECT * FROM `'. $table .'` WHERE `chrDate` > "'. $lastDate .'" INTO OUTFILE "'. $file .'"
FIELDS TERMINATED BY ", " ENCLOSED BY \'"\' ESCAPED BY "\\"
LINES TERMINATED BY "\n"';
于 2012-08-08T09:10:01.567 回答
0
  $a = "SELECT * FROM " . $table . " WHERE chrDate > '" . $lastDate . "' INTO OUTFILE '" . $file . "' 
        FIELDS TERMINATED BY ', ' ENCLOSED BY '\"' ESCAPED BY '\\' 
        LINES TERMINATED BY '\n'"; 
于 2012-08-08T09:10:37.853 回答