Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

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

:(

Update:

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

Muchas Gracias.

1 Answer

Relevance
  • Phreak
    Lv 5
    10 years ago
    Favorite Answer

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

Still have questions? Get your answers by asking now.