I am generating a csv file from MySQL with PHP / PDO. I put the header, generate the list but record them continuously.
<?php
require ('includes/config.php');
$BD = new ConnDB();
$archivo_csv = "saldos.csv";
if(!file_exists($archivo_csv)){
file_put_contents($archivo_csv,"Código,Nombre,Importe");
}
$sql = "SELECT cod, nom, saldo from cuentas where flag = 'X'";
$sth = $BD->query($sql);
$sth->execute();
if ($sth->rowCount() > 0) {
while ($fila = $sth->fetch(PDO::FETCH_ASSOC))
{
file_put_contents($archivo_csv,"n".join(",",$fila),FILE_APPEND);
}
}
?>
This is the exit:
Code, Name, Importen8, ALYDAR, 135.00n21, SANTA WATER, 1442.00n30
What is the error?