php5链接sql server2005的具体测试步骤。

1、测试环境

   操作系统:Win7

   数据库:SQL Server2005

   脚本语言:php 5.3

2、下载SQLServerDriverForPHP1.1 这个驱动,下载后并解压.

3、把解压后的文件php_sqlsrv_53_nts_vc9,php_sqlsrv_53_ts_vc9拷贝到C:\Program Files\php\ext里.

     注意:php_sqlsrv_53_nts_vc9(非线程安全),php_sqlsrv_53_ts_vc9(线程安全).

            C:\Program Files\php\ext 此路径为安装或解压php后的路径

        我查阅了下资料:如果是使用ISAPI的方式来运行PHP就必须用Thread Safe(线程安全)的版本;而用FastCGI模式运行PHP的话就没有必要用线程安全检查了,用None Thread Safe(NTS,非线程安全)的版本能够更好的提高效率。

        还有我们到底是用v6还是v9的dll,这个在php的官站上也有说明:

Which version do I choose?

If you are using PHP with Apache 1 or Apache2  from apache.org you need to use the VC6 versions of PHP [如果在apache服务器上,请用v6版本]

If you are using PHP with IIS you should use the VC9 versions of PHP [如果在iis里,请使用vc9版本]

VC6 Versions are compiled with the legacy Visual Studio 6 compiler

VC9 Versions are compiled with the Visual Studio 2008 compiler and have improvements in performance and stability. The VC9 versions require you to have the Microsoft 2008 C++ Runtime (x86) or the Microsoft 2008 C++ Runtime (x64)   installed

Do NOT use VC9 version with apache.org binaries

VC9 versions of Apache can be fetched at Apache Lounge. We use their binaries to build the Apache SAPIs.

 

4、C:\Program Files\php\php.ini文件打开,找到如下代码:

; Windows Extensions
; Note that ODBC support is built in, so no dll is needed for it.
; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)
; extension folders as well as the separate PECL DLL download (PHP 5).
; Be sure to appropriately set the extension_dir directive.
;

在上述代码下添加以下2行代码

extension=php_sqlsrv_53_ts_vc9.dll
extension=php_sqlsrv_53_nts_vc9.dll

5、安装sql server2008的sqlncli.Msi(去微软官站下载)

6、重启iis

--------------------------------------------------------------------------

以下是测试代码 2012-11-08

参数:$serverName 服务器名称,$uid为用户名,$pwd为密码

--------------------------------------------------------------------------

$serverName = "(local)";
$uid = "sa";
$pwd = "123";
$connectionInfo = array("UID"=>$uid,"PWD"=>$pwd,"Database"=>"LK.SQLDB");
$conn = sqlsrv_connect($serverName,$connectionInfo);
if( $conn == false){
   echo "连接失败!";
   //die(print_r(sqlsrv_errors(), true));
}
else{
   //echo "successful";
}

$tsql="select lID,[Name] from [LK_DiQu] order by lID desc";
$stmt = sqlsrv_query($conn,$tsql);
echo "<ul>";
while( $row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC))
{
     echo '<li>'.$row["Name"].'</li>';
}
echo "<ul>";
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值