使用MSSQL未定义函数sqlsrv_exec()选择语句


Select statement using MSSQL - undefined function sqlsrv_exec()

我正在使用xampp, PHP, and MSSQL。我需要从MSSQL数据库中执行SELECT语句。目前,我只与MSSQL建立了连接,发现很难对DB中的dbo.My_TABLE执行SELECT语句。

我的代码如下所示;

并且错误我得到Fatal error: Call to undefined function sqlsrv_exec() i

$ser = "COMP'DEF";
$co = array( "Database"=>"IST");
$conn = sqlsrv_connect( $seR, $CO);
if(! $conn ) {
     echo "failed.";
}

if ($conn) 
{ 
  //the SQL statement that will query the database 
  $query = "select * from dbo.MY_TABLE"; 
  //perform the query 
  $result=sqlsrv_exec($conn, $query); 

  //print field name 
  $colName = sqlsrv_num_fields($result); 
  for ($j=1; $j<= $colName; $j++) 
  {  
    echo "<th>"; 
    echo sqlsrv_field_name ($result, $j ); 
    echo "</th>"; 
  } 
  //fetch tha data from the database 
  while(sqlsrv_fetch_row($result)) 
  { 
    echo "<tr>"; 
    for($i=1;$i<=sqlsrv_num_fields($result);$i++) 
    { 
      echo "<td>"; 
      echo sqlsrv_result($result,$i); 
      echo "</td>"; 
    } 
    echo "</tr>"; 
  } 
  echo "</td> </tr>"; 
  echo "</table >"; 
  //close the connection 
  sqlsrv_close ($conn); 
} 
?>

尝试将其替换为sqlsrv_execute

以下是手册和示例:

http://www.php.net/manual/en/function.sqlsrv-execute.php

相关文章: