I'm having problems creating csv files with fputcsv. The fact is that I go through the database while I show the columns and keep them in the csv, but in the loop, I also make a call to a function which returns a string. I make an array_push to add it to the array that contains the rows and I get an error: fputcsv () expects parameter 2 to be array, integer given. I leave the code for you to understand me better:
$resultados = Yii::app()->db->createCommand($query)->queryAll();
//Consulta SQL
json_encode(array('response' => 'true'));
mb_internal_encoding("UTF-8");
$codificacion = mb_internal_encoding();
try {
//Fichero
$archivo=fopen(getcwd()."/assets/log/".$nombre_fichero."_".$date.".csv","a+");
//Cabecera
fputcsv($archivo, $cabecera, $delimeter);
foreach ($resultados as $line) {
$direcciones = $this->direcciones($token, $line, $archivo, $codificacion);
$lines = array_push($line, $direcciones);
fputcsv($archivo, $lines, $delimeter);//Aquí me da el error en el parámetro 2
}
} catch (Exception $e) {
fputs($archivo,"Error al crear fichero CSV-> Error: ".$e->getMessage().PHP_EOL);
}
fclose($archivo);