php 连接sqlserver方法

1.下载SQL Server Driver for PHP,解压缩后,将php_pdo_sqlsrv_53_ts_vc9.dll和php_sqlsrv_53_ts_vc9.dll拷贝到php-->ext文件夹下

2.修改php.ini 文件,

extension=php_pdo_sqlsrv_53_ts_vc9.dll

extension=php_sqlsrv_53_ts_vc9.dll

3.测试是否设置成功

在PHP中执行phpinfo()的查看sqlsrv

4.demo测试

<?php

$type = $_GET["tp"];
$param =$_GET["prm"];

if( isset($_GET["tp"]) &&isset ($_GET["prm"]) )
{
    $userInfo=new UserInfo();
    if($type=="select" && $param== "all")
        echo $userInfo->SelectAll();
        
}

class UserInfo
{

    public function SelectAll()
    {
        $serverName = "192.168.1.8"; //数据库服务器地址
        $uid = "sa"; //数据库用户名
        $pwd = "1234?"; //数据库密码
        $connectionInfo = array("UID"=>$uid, "PWD"=>$pwd, "Database"=>"DB");
        $conn = sqlsrv_connect( $serverName, $connectionInfo);
        
        if( $conn == false)
        {
            echo "连接失败!";
            die( print_r( sqlsrv_errors(), true));
        }
        
        $res="";
        $query = sqlsrv_query($conn, "select * from UserInfo");
        while($row = sqlsrv_fetch_array($query))
        {
          $res.=$row[0].",".$row[1]."|";
        }
        return $res;
    }

}
?>


ok~~~~~

 

php 连接sqlserver方法,布布扣,bubuko.com

php 连接sqlserver方法

上一篇:System.Data.Dbtype转换为System.Data.SqlDbType


下一篇:sql server 本地复制订阅 实现数据库服务器 读写分离(转载)