I am trying to export data from MSSQL table to Excel. Below is my code. Problem is that i am getting the following error:
Fatal error: Call to undefined function mssql_fetch_array() in C:xampp\code.php on line 25
I am running Windows Server 2008 R2, IIS7, SQL Server 2008, PHP Version 5.4.4.
I have un-commented the line: "extension=php_mssql.dll" found in C:\xampp\php\php.ini
<?php
// load library
require 'include\php-excel.class.php';
$i = 0; // used as a counter
$myServer = "SERVERNAME\SQLEXPRESS";
$myUser = "UserName";
$myPass = "xxxxxx";
$myDB = "dbName";
$conn = new COM ("ADODB.Connection") or die("Cannot start ADO");
$connStr = "PROVIDER=SQLOLEDB;SERVER=".$myServer.";UID=".$myUser.";PWD=".$myPass.";DATABASE=".$myDB;
$conn->open($connStr); //Open the connection to the database
$result = "SELECT Col1, Col2, Col3 FROM myTable WHERE Col3='myCondition'";
//$rs = $conn->execute($result);
//$num_columns = $rs->Fields->Count();
// create data array and print headers on the first row
$data = array(1 => array ('No.', 'Col1', 'Col2', 'Col3'));
while($row=mssql_fetch_array($result)) {
//include additional rows
array_push($data, array($i, $row['Col1'], $row['Col2'], $row['Col3']));
$i++;
}
// If no results, indicate this on the first row
if ($i == 0){
$data = array(1 => array ('No results', 'empty', 'empty', 'empty'));
}
//generate file (constructor parameters are optional)
$xls = new Excel_XML('UTF-8', false, 'My Test Sheet');
$xls->addArray($data);
$xls->generateXML('MyReport');
?>
Thank you in advance.
phpinfo()'s outputphpinfo()and see if the MS SQL functions are enabled.