Whats wrong with my MySql Query? (or PHP code...)?

<?php
require_once('../includes/dbstuff.php');
$export_table = 'merchant_account';
$term = ',';
$newline = '\n';
$optenc = '"';
$escape = "\\";
$sql = "SELECT email, current_balance, currency, track_number, track_notes FROM $export_table INTO OUTFILE '/home/lizix/public_html/OUTFILE.csv' FIELDS TERMINATED BY '$term' OPTIONALLY ENCLOSED BY '$optenc' ESCAPED BY '$escape' LINES TERMINATED BY '$newline'";

echo "$sql <br><br>";
$export = mysql_query($sql) or die (mysql_error());
?>

Yields:

SELECT email, current, currency, track, track_notes FROM merchant_account INTO OUTFILE '/home/lizix/public_html/OUTFILE.csv' FIELDS TERMINATED BY ',' OPTIONALLY 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 1

:(

2011-10-09T14:26:07Z

Thanks Phreak! That wasn't quite it, it was in the ESCAPED BY var.. but it was a backslash issue..
Muchas Gracias.

Phreak2011-10-09T14:20:43Z

Favorite Answer

You can't include a solitary slash in a string as it's seen as a special character, try \\n instead