I am trying to:
- create comma delimited .csv file with php code.
 - Insert column name in the first line of the .csv file.
 
Please advise how can I make this happen.
    <?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";  
    }?>
