PHP连接MSSQL2008/2005数据库(SQLSRV)配置

本文实例陈说了PHP连接MSSQL二零一零/二零零五数据库(SQLSTiguanVState of Qatar配置格局,分享给大家供我们参谋。具体方法如下:

1.下载扩充

PHP连接MSSQL二零一零/二零零七数据库与往常的三回九转mssql二〇〇三是不生机勃勃致的,连接mssql二〇一〇/二零零五是亟需和谐增添PHP对MSSQL连接的驱动扩张了,而作者辈常用的hp.ini中的extension=php_mssql.dll扩充只适用连接于MSSQL二零零零,下边我们就来探视对此的清除办法

(1)去官方下载三个SQL Server Driver for
PHP的恢宏包,笔者是在那间下载的
  (2)您也足以直接从本站下载(作者事情发生前下载的,来源于microsoft官方)【
点击直接下载 】
将下载下来的rar文件解压后你就能收获一群的.dll文件

1.下载扩充

下载驱动程序,下载后装置释放程序,里面有以下文件:

(1)去官方下载二个SQL Server Driver for
PHP的扩充包,小编是在此边下载的

php_pdo_sqlsrv_52_nts.dll

(2)您也足以向来从本站下载(小编事情未发生前下载的,来源于microsoft官方)【点击这里直接下载.rar)】
将下载下来的rar文件解压后您就能够拿到一群的.dll文件

php_pdo_sqlsrv_52_ts.dll

下载驱动程序,下载后装置释放程序,里面有以下文件:
php_pdo_sqlsrv_52_nts.dll
php_pdo_澳门新葡萄京娱乐场,sqlsrv_52_ts.dll
php_pdo_sqlsrv_53_nts_vc6.dll
php_pdo_sqlsrv_53_nts_vc9.dll
php_pdo_sqlsrv_53_ts_vc6.dll
php_pdo_sqlsrv_53_ts_vc9.dll
php_sqlsrv_52_nts.dll
php_sqlsrv_52_ts.dll
php_sqlsrv_53_nts_vc6.dll
php_sqlsrv_53_nts_vc9.dll
php_sqlsrv_53_ts_vc6.dll
php_sqlsrv_53_ts_vc9.dll
SQLServerDriverForPHP.chm(手册,意大利语够好的话,能够看看,嘿嘿)
SQLServerDriverForPHP_License.rtf
SQLServerDriverForPHP_Readme.htm(自述文件)

php_pdo_sqlsrv_53_nts_vc6.dll

2.增加扩充

php_pdo_sqlsrv_53_nts_vc9.dll

听大人说(vc6/vc9卡塔尔国需求接收增加,作者的意况是WAMP(php5.2.6/apache2.2.8卡塔尔国,作者选择的是php_sqlsrv_52_ts_vc6.dll,php_pdo_sqlsrv_52_ts_vc6.dll那多个文件,复制到wamp安装目录下的ext目录下,作者的ext目录是在wamp/bin/php/php5.2.6/ext/

php_pdo_sqlsrv_53_ts_vc6.dll

3.配置php.ini

php_pdo_sqlsrv_53_ts_vc9.dll

(1)在php.ini的Dynamic Extensions中加多如下两条扩大:
    extension=php_sqlsrv_52_ts_vc6.dll
    extension=php_pdo_sqlsrv_52_ts_vc6.dll
(2)将;extension=php_pdo.dll前边的;去掉,开启pdo连接扩大
(3)重新起动apache

php_sqlsrv_52_nts.dll

4.连接数据库(pdo连接卡塔尔

php_sqlsrv_52_ts.dll

复制代码 代码如下:  
$servern=”SFKFK27EL8FJ\SQLTXC90Y”;
 
$coninfo=array(“Database”=>”try2″,”UID”=>”sa”,”PWD”=>”123″);
  $conn=sqlsrv_connect($servern,$coninfo卡塔尔 or die (“连接战败!”);
  $val=sqlsrv_query($conn,”select * from usertable”);
  while($row=sqlsrv_fetch_array($val)){
    echo $row[1].”
“;
  }
  sqlsrv_close($conn);
?>

php_sqlsrv_53_nts_vc6.dll

**5.例子

php_sqlsrv_53_nts_vc9.dll

**链接示例:
mssql_lib.php文件如下:

php_sqlsrv_53_ts_vc6.dll

复制代码 代码如下: class DB {
    var $con = null;
    function __construct($dbhost,$dbuser,$dbpass,$dbname) {
        $connectionInfo = 
array(“UID”=>$dbuser,”PWD”=>$dbpass,”Database”=>$dbname);
        $this->con = sqlsrv_connect($dbhost,$connectionInfo);
    }
    function query($sql){
        $result = sqlsrv_query($this->con, $sql);
    }
    function getRow($sql){
        $result = sqlsrv_query($this->con, $sql);
        $arr = array();
        while($row = sqlsrv_fetch_array($result))
        {
            $arr[] = $row;
        }
        return $arr[0];
    }
    function getAll($sql){
        $result = sqlsrv_query($this->con, $sql);
        $arr = array();
        while($row = sqlsrv_fetch_array($result))
        {
            $arr[] = $row;
        }
        return $arr;
    }
    function __destruct() {
        unset($con);
    }
}

php_sqlsrv_53_ts_vc9.dll

test.php页面如下:
复制代码 代码如下://简单调用
$db = new DB(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$sql = “select * from crm_order_batch where (status=0 or status is
null) and lock_id is not null  “;
$orders_add_list = $db->getAll($sql);

SQLServerDriverForPHP.chm(手册,俄文够好的话,能够看看,嘿嘿)

可望本文所述对我们的PHP数据库程序设计有着支持。

SQLServerDriverForPHP_License.rtf

SQLServerDriverForPHP_Readme.htm(自述文件)

2.增加恢弘

 
根据(vc6/vc9卡塔尔国须要选用增加,作者的意况是WAMP(php5.2.6/apache2.2.8卡塔尔国,小编选用的是php_sqlsrv_52_ts_vc6.dll,php_pdo_sqlsrv_52_ts_vc6.dll那七个文件,复制到wamp安装目录下的ext目录下,作者的ext目录是在wamp/bin/php/php5.2.6/ext/

3.配置php.ini

(1)在php.ini的Dynamic Extensions中加多如下两条扩张:
    extension=php_sqlsrv_52_ts_vc6.dll
    extension=php_pdo_sqlsrv_52_ts_vc6.dll

(2)将;extension=php_pdo.dll后边的;去掉,开启pdo连接扩张

(3)重新开动apache
4.连接数据库(pdo连接)

 代码如下

<?php
  $servern=”SFKFK27EL8FJ\SQLTRY”;
 
$coninfo=array(“Database”=>”try2″,”UID”=>”sa”,”PWD”=>”123″);
  $conn=sqlsrv_connect($servern,$coninfo卡塔尔国 or die (“连接退步!”);
 
$val=sqlsrv_query($conn,”select
* from usertable”);
  while($row=sqlsrv_fetch_array($val)){
    echo $row[1].”<br />”;
  }
  sqlsrv_close($conn);
?>

5.例子

链接示例:

mssql_lib.php

 代码如下

<?php

class DB {
    var $con = null;
    function __construct($dbhost,$dbuser,$dbpass,$dbname) {
        $connectionInfo = 
array(“UID”=>$dbuser,”PWD”=>$dbpass,”Database”=>$dbname);
        $this->con = sqlsrv_connect($dbhost,$connectionInfo);
    }

    function query($sql){
        $result = sqlsrv_query($this->con, $sql);
    }

    function getRow($sql){
        $result = sqlsrv_query($this->con, $sql);
        $arr = array();
        while($row = sqlsrv_fetch_array($result))
        {
            $arr[] = $row;
        }
        return $arr[0];
    }

    function getAll($sql){
        $result = sqlsrv_query($this->con, $sql);
        $arr = array();
        while($row = sqlsrv_fetch_array($result))
        {
            $arr[] = $row;
        }
        return $arr;
    }

    function __destruct() {
        unset($con);
    }

}
test.php

//不难调用
$db = new DB(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$sql = “select * from crm_order_batch where (status=0 or status is
null) and lock_id is not null  “;
$orders_add_list = $db->getAll($sql);

发表评论

电子邮件地址不会被公开。 必填项已用*标注