zoukankan      html  css  js  c++  java
  • linux centos6.4 php连接sql server2008

    1、安装SQL Server驱动freetds

    yum search freetds
    
    yum install freetds php-mssql

    或者下载编译安装

     
    2、修改/etc/freetds.conf
     

    [server2008]

            host = 192.168.70.119

            port = 1433

            tds version = 7.0

        client charset = utf8

     
     最好重启一下apache
    3、测试连接
     
    ./tsql -S 192.168.0.109 -U 用户名 -P 密码 -D 数据库
    如果可以有看到1>说明连接成功
    输入sql语句
    1>select * from table;
    2>go
     
    4、代码测试连接
     
    <?php
    $server = 'server2008 ';
    $link = mssql_connect($server, 'sa', '123456');
    if (!$link) {
    die('Something went wrong while connecting to MSSQL');
    }
    ?>

     5、测试PDO连接Sql server

    这里用到了dblib

    <?php
    $db = new PDO("dblib:host=192.168.70.119;dbname=master","sa","123456");
    $sql = "select top 3 *  from spt_values";
    $res = $db->query($sql);
    while ($row = $res->fetch()){
      print_r($row);
    }
    $res = null;
    $db = null;
    ?>

    结果:

    Array ( [name] => jiqing [0] => jiqing [number] => 1 [1] => 1 [type] => A [2] => A [low] => [3] => [high] => [4] => [status] => 0 [5] => 0 ) Array ( [name] => pub [0] => pub [number] => 2 [1] => 2 [type] => A [2] => A [low] => [3] => [high] => [4] => [status] => 0 [5] => 0 ) Array ( [name] => sub [0] => sub [number] => 4 [1] => 4 [type] => A [2] => A [low] => [3] => [high] => [4] => [status] => 0 [5] => 0 )

  • 相关阅读:
    LeetCode (Two Sum & Add Two nums)
    打包时记录编译开始时间并在App中获取
    CocoaPods
    不知所云
    苹果审核相关内容
    iOS权限的一些备注
    触发网络权限弹窗的一些特别方式记录
    iOS13和iOS14里面访问相册选取图片的两种方式的区别
    @Configuration@Bean
    ACID
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/3370396.html
Copyright © 2011-2022 走看看