【发布时间】:2015-04-07 19:25:41
【问题描述】:
我需要一些帮助才能从 SQL Server 查询导出到 csv。
我有查询,但是当我获取结果时,我需要将它放在一个变量上并导出它。
这就是我所拥有的:
$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);
【问题讨论】:
-
我不确定问题到底是什么。你可以说得更详细点吗?您在探索 csv 查询的哪一部分遇到问题?
-
我需要将查询结果放入 $list 变量中,这就是我的问题所在,如何将其传递给 $list 变量。
标签: php sql-server csv odbc