我想:
请告知我该如何实现这一目标。
<?php
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=".$batch_id.".csv");
header("Pragma: no-cache");
header("Expires: 0");
$conn_sp = mssql_connect("SQLServer", "user", "password");
$db_sp = mssql_select_db("databaseName", $conn_sp);
$stmt = mssql_init("[StoredProcedureName]",$conn_sp);
mssql_bind($stmt, "@BatchNo", $batch_id, SQLVARCHAR, FALSE, FALSE, 20);
$result = mssql_query("SET ANSI_NULLS ON");
$result = mssql_query("SET ANSI_WARNINGS ON");
$result = mssql_execute($stmt);
$record="";
$comma=",";
$record_end="\n";
while ($row = mssql_fetch_array($result, MSSQL_ASSOC)){
foreach ($row as $key => $value) {
echo $value;
}
echo "\n";
}?>
答案 0 :(得分:0)
好好看看如何创建.csv文件。
通常是这样的:
分隔符:,
换行:\ n
附上条目:“
e.g。
“r1a”,“r1b”,“r1c”
“r2a”,“r2b”,“r2c”
等...
这是您的代码应该如何工作(未经测试):
echo '"colname1","colname2",...';
while ($row = mssql_fetch_array($result, MSSQL_ASSOC)){
$first = true;
foreach ($row as $key => $value) {
if(!$first) {
echo ",";
}
echo '"'.$value.'"';
}
echo "\n";
$first=false;
}