php sqlserver扩展,PHP---连接sqlserver扩展配置

本人环境Apache:2.2.21 php:5.3.10 操作系统windows xp service pack 3

使用的是Microsoft Drivers for PHP for SQL Server的扩展包做连接。

1.下载Microsoft Drivers for PHP for SQL Server 扩展包 它分为2.0和3.0版

本。(本人使用的是2.0版本)

这个扩展包对电脑的操作系统有要求,对应的系统使用对应的版本。

3.0 所支持的操作系统

Windows Server 2008 R2 SP1

Windows Vista SP2

Windows Server 2008 SP2

Windows 7 SP1

2.0 所支持的操作系统

Windows Server 2003 Service Pack 1

Windows XP Service Pack 3

Windows Vista Service Pack 1 or later

Windows Server 2008

Windows Server 2008 R2

Windows 7

所以本次实例使用的是 2.0 里面php_sqlsrv_53_ts_vc9.dll 扩展

;

2.将php_sqlsrv_53_ts_vc9.dll文件复制到php的扩展文件夹 (一般的都在

php/ext文件夹下面);

3.将此php_sqlsrv_53_ts_vc9.dll文件拷贝到系统所在盘的system32中;

4.打开php.ini文件,在extension=php_mysql.dll 下面一行添加

extension=php_sqlsrv_53_ts_vc9.dll 之后重启apache。

5.测试代码

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

$serverName = "127.0.0.1";

$uid = "sa";

$pwd = "000";

$db = "php555";

$connectionInfo = array(

"UID"=$uid,"PWD"=$pwd,"Database"=$db

);

$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn === false )

{

echo "Unable to connect.";

die(var_dump( sqlsrv_errors(), true));

}else{

echo "sqlserver连接成功!!!";

}

6.运行上边代码会提示您以下内容

Unable to connect.

array(2) { [0]=> array(6) { [0]=> string(5) “IMSSP”

["SQLSTATE"]=>

string(5) “IMSSP” [1]=> int(-49) ["code"]=> int(-49) [2]=>

string(390)

“This extension requires either the Microsoft SQL Server 2008

Native

Client (SP1 or later) or the Microsoft SQL Server 2008 R2 Native

Client

ODBC Driver to communicate with SQL Server. Neither of those

ODBC

Drivers are currently installed. Access the following URL to

download

the Microsoft SQL Server 2008 R2 Native Client ODBC driver for

x86:

["message"]=>

string

(390) “This extension requires either the Microsoft SQL Server

2008

Native Client (SP1 or later) or the Microsoft SQL Server 2008 R2

Native

Client ODBC Driver to communicate with SQL Server. Neither of

those

ODBC Drivers are currently installed. Access the following URL

to

download the Microsoft SQL Server 2008 R2 Native Client ODBC driver

for

x86: } [1]=>

array(6) {

[0]=> string(5) “IM002″ ["SQLSTATE"]=> string(5) “IM002″

[1]=> int(0)

["code"]=> int(0) [2]=> string(71) “[Microsoft][ODBC 驱动程序管理器]

发现数据源名称并且未指定默认驱动程序” ["message"]=> string(71)

“[Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程

序” } } bool(true)

7.点击 这个链接 进入下载驱

动程序包就可以了,X86 Package(sqlncli.msi) 。安装的时候有可能某些软件会影响到安装,导致安装失败,

建议您关掉没用的程序。

8.之后再运行第5步代码; 提示:”sqlserver连接成功!!!” 。

9.具体的sqlsrv的函数就不做介绍了 在扩展包里面有手册,手册里面有详细介绍。

(转载请注明出处,谢谢)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值