Generate Excel from SQL Server database using stored procedure and PHP?

Viewed 36

I have been trying to generate Excel from a SQL Server database with the help of a stored procedure and PHP code. But it is not generating Excel whenever I am using stored procedure but when I am using single a SQL statement it is generating Excel. In my error log there are no errors are getting generated. I am sharing my stored procedure with my PHP code for generating Excel.

<?php include('connection.php'); ?>  
    <table border="1">
    <thead>
        <tr>
            <th>OBIPAN</th>
            <th>OBIPOS</th>
            <th>STATUSRESPONSE</th>
        </tr>
    </thead>        
<?php 
// File name 
$filename = "EmpData"; 

// Fetching data from data base
$stmt = "{ CALL Ins_OtherKRA_Modification (@filepath = ?)}"; 
$filepath = ''; 
$params = array (array($filepath, SQLSRV_PARAM_IN)); 
$result = sqlsrv_query( $conn, $stmt,$params);
$cnt = 1;
while ($row=sqlsrv_fetch_array($result)) {      
?>
        <tr>
                <td><?php echo $cnt;  ?></td>
                <td><?php echo $row['OBIPAN'];?></td>
                <td><?php echo $row['OBIPOS'];?></td>
                <td><?php echo $row['STATUSRESPONSE'];?></td>
        </tr> 
<?php  
    $cnt++; 
    // Genrating Execel  files 
    header("Content-type: application/octet-stream"); 
    header("Content-Disposition: attachment; filename=".$filename."-Report.xls"); 
    header("Pragma: no-cache"); 
    header("Expires: 0");
} ?>
    </table>

My stored procedure has only one parameter @filepath.

0 Answers
Related