• 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~~~~~

  • 相关阅读:
    selenium之css选择器高级用法
    常系数线性齐次递推新理解
    关于莫队本质的理解
    2021.5.8总结
    决策单调性优化dp
    字符串 复习
    5.1总结
    树分块 学习笔记
    莫反 复习
    P4570 [BJWC2011]元素
  • 原文地址:https://www.cnblogs.com/lijun2013/p/3810634.html
Copyright © 2020-2023  润新知