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);
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效