dongtaigan1594 2018-12-12 03:59
浏览 271
已采纳

无法连接到mssql服务器或sqlsrv没有显示在phpinfo上

i have problem to connect to server, i did all the step from here and i already change php.ini On windows: extension_dir = "D:\xampp\php\ext" but i still cant connect, My PHP Version is 7.2.11 i tried with mssql_connect() and sqlsrv_connect()

here my

`<?php
$servername = "1111";
$username = "user";
$password = "123";
$dbname = "DEV";
$connection = mssql_connect($servername, $username, $password);
if (!$connection) {  die('Not connected : ' . mssql_get_last_message());} 
$db_selected = mssql_select_db($dbname, $connection);
if (!$db_selected) {
  die ('Can\'t use db : ' . mssql_get_last_message());
} else{
echo "success";} ?>`
  • 写回答

1条回答 默认 最新

  • dongzhuo5185 2018-12-12 06:51
    关注

    MSSQL extension for PHP (mssql_ functions) and PHP Driver for SQL Server (sqlsrv_ functions) are two different extensions for PHP.

    MSSQL extension is not available anymore on Windows with PHP 5.3 or later, so you need to install PHP Driver for SQL Server. You need to download appropriate version of this driver. For PHP 7.2 - version 5.2 or 5.3 (32-bit or 64-bit also depends on PHP version). Also download and install an appropriate ODBC driver.

    Check the configuration with <?php phpinfo();?>. There should be a section with name pdo_sqlsrv (if you use PDO) and/or sqlsrv (without PDO).

    Example:

    <?php
    $server   = '1111';
    $database = 'DEV';
    $uid      = 'user';
    $pwd      = '123';
    
    # SQL Server authentication
    #$cinfo = array(
    #    "Database" => $database,
    #    "UID" => $uid,
    #    "PWD" => $pwd
    #);
    
    # Windows authentication
    $cinfo = array(
        "Database" => $database
    );
    
    $conn = sqlsrv_connect($server, $cinfo);
    if ($conn === false) {
        echo "Error (sqlsrv_connect): ".print_r(sqlsrv_errors(), true);
        exit;
    } else {
        echo "success";
    }
    
    sqlsrv_close($conn);
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)