php连接sqlserver总结

By | 2016年3月16日

1、如果用sqlsrv连接失败了可以用以下代码查看错误原因:

1
2
        if(sqlsrv_connect($this->hostname, $connection)==false)
            print_r(sqlsrv_errors());

另外可以从这里获取sqlsrv的帮助:https://msdn.microsoft.com/zh-cn/library/cc296161(v=SQL.90).aspx

2、如果出现如下错误则表示没有安装Native Client插件,请在指定页面安装:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Array
(
    [0] => Array
        (
            [0] => IMSSP
            [SQLSTATE] => IMSSP
            [1] => -49
            [code] => -49
            [2] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712
            [message] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712
        )

    [1] => Array
        (
            [0] => IM002
            [SQLSTATE] => IM002
            [1] => 0
            [code] => 0
            [2] => [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序
            [message] => [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序
        )

)

软件名称:Native Client
下载页面:http://go.microsoft.com/fwlink/?LinkId=163712
php5.3的Microsoft? SQL Server? 2012 Native Client下载页面:https://www.microsoft.com/zh-CN/download/details.aspx?id=29065

3、如果用xampp安装的环境,可能没有连接sql数据库的dll扩展,需要自己下载。另知乎说:自从php5.3.6,PHP官方不再为mssql提供mssql扩展,要从第三方网站下载,不知真假。
软件名称:Microsoft Drivers for PHP for SQL Server
下载链接:https://www.microsoft.com/en-us/download/details.aspx?id=20098

Category: PHP

发表回复