Scott_Huang 2013-07-18 16:51:41 3050次浏览 0条回复 0 0 0
  1. 下载 SQL ext http://www.microsoft.com/en-us/download/details.aspx?id=20098

  2. 解压到php\ext\中

  3. PHP.ini 加入

extension=php_sqlsrv_54_ts.dll
extension=php_pdo_sqlsrv_54_ts.dll

4.重启Apache, ok.

Btw, I use XAMPP v3.2.1. And below is one of Sample:

<?php

$serverName = "Your Server name";
$connectionInfo = array( "Database"=>"Your database");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false )
{
     echo "Could not connect database\n";
     die( print_r( sqlsrv_errors(), true));
}
  
$server_info = sqlsrv_server_info( $conn);
if( $server_info )
{
      foreach( $server_info as $key => $value)
      {
             echo $key.": ".$value."\n<BR><BR>";
      }
}
else
{
      echo "Error in retrieving server info.\n<BR>";
      die( print_r( sqlsrv_errors(), true));
}


/* Set up and execute the query. Note that both ReviewerName and
Comments are of SQL Server type nvarchar. */
$tsql = "select *  
         FROM tbl_status
         ";
$stmt = sqlsrv_query( $conn, $tsql);
if( $stmt === false )
{
     echo "Error in statement preparation/execution.\n";
     die( print_r( sqlsrv_errors(), true));
}
/* Retrieve the number of fields. */
$numFields = sqlsrv_num_fields( $stmt );

/* Iterate through each row of the result set. */
while( sqlsrv_fetch( $stmt ))
{
     /* Iterate through the fields of each row. */
     for($i = 0; $i < $numFields; $i++)
     {
          echo sqlsrv_get_field($stmt, $i, 
                   SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR))." ";
     }
     echo "<BR>\n";
}

sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
    没有找到数据。
您需要登录后才可以回复。登录 | 立即注册