zoukankan      html  css  js  c++  java
  • php连接SQL server 数据库测试php脚本

    以下是php7上的测试 sqlsrv扩展

    <?php
    header("Content-type: text/html; charset=utf-8");
            $serverName = "192.168.0.1"; //数据库服务器地址
            $uid = "site_user"; //数据库用户名
            $pwd = "zkJ1246g"; //数据库密码
            $connectionInfo = array("UID"=>$uid, "PWD"=>$pwd, "Database"=>"db_site");
            $conn = sqlsrv_connect( $serverName, $connectionInfo);
            if( $conn == false)
            {
                    echo "连接失败!";
                    die( print_r( sqlsrv_errors(), true));
            }else{
                    echo "连接成功!";
            }
            #$query = sqlsrv_query($conn, "select * from 数据库表");
            #while($row = sqlsrv_fetch_array($query))
            #{
            #  print_r($row);
            #}
    ?>
    

    以下是php5上的测试dblib扩展

    <?php
    
     try {
        $hostname = "192.168.17"; 
        $dbname = "lee";
        $username = "le2r"; 
        $pwd = "le52"; 
        $dsn="dblib:host=$hostname;dbname=$dbname;charset=UTF-8";
    
       $conn = new PDO ($dsn,$username,$pwd);
       $conn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
       echo "mssql database connnection sucessed!
    ";
       } catch (PDOException $e) {
       echo "Failed to get DB handle: " . $e->getMessage() . "
    ";
       exit;
       }
    
    ?>
    

      

  • 相关阅读:
    java 基本功
    orale问题汇总
    redis 集群
    centos7 之 systemctl
    redis 常见问题记录
    docker问题汇总
    sql plus 导出建表语句
    linux 添加删除用户
    mysql常用配置
    SAS 查看临时数据集
  • 原文地址:https://www.cnblogs.com/xzlive/p/12792499.html
Copyright © 2011-2022 走看看