I need some help to export from a SQL Server query to csv.
I have the query but when I'm fetching the result I need to put it on an variable and export it.
This is what I have:
$query = 'select * from sqlserver_table';
$result = odbc_exec($conMsSql,$query);
// this gives me the columns
while(odbc_fetch_row($result)){
$field1 = odbc_result($result, 1);
$field2 = odbc_result($result, 2);
$field3 = odbc_result($result, 3);
$field4 = odbc_result($result, 4);
$field5 = odbc_result($result, 5);
$field6 = odbc_result($result, 6);
$field7 = odbc_result($result, 7);
}
// this is to export
$file = fopen("export.csv","w");
foreach ($list as $line){ // how can I put the result in this variable ($list)?
fputcsv($file,explode(',',$line));
}
fclose($file);