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

时间:2012-08-28 11:19:00

标签: php sql sql-server

我正在使用xampp, PHP, and MSSQL。我需要从SELECT db做一个MSSQL语句。目前我只与MSSQL建立了连接,发现很难从数据库中对SELECT发出dbo.My_TABLE声明。

我的代码如下;

,错误我得到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); 
} 

?>

1 个答案:

答案 0 :(得分:0)

尝试将其替换为sqlsrv_execute

以下是手册和示例:

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