我正在尝试将数据从 MSSQL 表导出到 Excel。下面是我的代码。问题是我收到以下错误:
Fatal error: Call to undefined function mssql_fetch_array() in C:xampp\code.php on line 25
我正在运行 Windows Server 2008 R2、IIS7、SQL Server 2008、PHP 版本 5.4.4。
我已取消注释该行:“extension=php_mssql.dll”在 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');
?>
先感谢您。