bbruman bbruman - 19 days ago 5
MySQL Question

Empty Lines at End of TSV file Creating Empty Column in MySQL Load Data Infile

What's the best way to amend this issue, in either MySQL or PHP?

I'm using the Amazon PHP SDK, GetReport function.

$intry = (stream_get_contents($request->getReport()) . "\n");
$merchantalldata = '_GET_MERCHANT_LISTINGS_ALL_DATA_' . $today0 . '.tsv';
file_put_contents($merchantalldata,$intry);

$sql = "LOAD DATA LOCAL INFILE '_GET_MERCHANT_LISTINGS_ALL_DATA_" . $today00 . ".tsv' INTO TABLE . . . . "


Always on my returned TSV, it's always the same:

enter image description here
enter image description here

How can I fix this issue, whether in the TSV file itself, via PHP, or disallow this blank entry from being inserted in the MySQL database?

Answer

Remove the "\n" in the stream_get_contents() call, then trim() if needed:

$intry = trim(stream_get_contents($request->getReport()));
Comments