Centos7 Php7到Sqlsrv / ODBC连接错误

时间:2018-11-28 08:56:52

标签: php sql-server odbc centos7 sqlsrv

我正在尝试连接Windows Server 2008,这是mssql服务器。我可以从其他虚拟Windows 10 xampp服务器(已安装所有要求)开始进行连接。 SQL Server端口已打开并准备就绪。我确定。所有服务器都是本地服务器。

我可以通过Centos 7终端连接到该服务器。使用 tsql 命令,我可以连接远程sql服务器并在那里查询。但是我无法连接php。

我尝试了sqlsrv和odbc。结果相同。在此处找不到服务器。

我应该尝试什么?

<?php

$server = '192.168.1.18'; // I tried add "\SQLEXPRESS" noting changed. 
$user = 'SA';
$pass = 'ob@XXXXXX';
$port='Port=1433';
$database = 'LOGO';

$connection_string = "DRIVER={ODBC Driver 17 for SQL Server};SERVER=$server;$port;DATABASE=$database";
$conn = odbc_connect($connection_string,$user,$pass);
if ($conn) {
    echo "Connection established.";
} else{
    echo "Connection could not be established.<HR><HR>";
}


    $serverName = "192.168.1.18"; // I TRIED TO ADD PORT ALSO ",1433" BUT NOTING CHANGED.
    $connectionInfo = array(
        "Database"=>"LOGO",
         "UID"=>"SA", "PWD"=>"ob@XXXXXX",
         "CharacterSet" => "UTF-8",
         "ConnectionPooling" => "0"
    );

    //Establishes the connection
    $conn = sqlsrv_connect($serverName, $connectionInfo);
    if($conn)
        echo "Connected!";

    if( $conn === false ) {
        die( print_r( sqlsrv_errors(), true ));
    }
  


  警告:odbc_connect():SQL错误:[unixODBC] [Microsoft] [用于SQL Server的ODBC驱动程序17]登录超时已到期,在 / var / www / html /中的SQLConnect中的SQL状态S1T00 25
行上的XXX / oba / MVC / controllers / deneme_c.php
  


数组   (       [0] =>数组           (               [0] => HYT00               [SQLSTATE] => HYT00               [1] => 0               [代码] => 0               [2] => [unixODBC] [Microsoft] [SQL Server的ODBC驱动程序17]登录超时已过期               [消息] => [unixODBC] [Microsoft] [SQL Server的ODBC驱动程序17]登录超时已过期           )

[1] => Array
    (
        [0] => 08001
        [SQLSTATE] => 08001
        [1] => -1
        [code] => -1
        [2] => [unixODBC][Microsoft][ODBC Driver 17 for SQL Server]MAX_PROVS: Error Locating Server/Instance Specified [xFFFFFFFF]. 
        [message] => [unixODBC][Microsoft][ODBC Driver 17 for SQL Server]MAX_PROVS: Error Locating Server/Instance Specified [xFFFFFFFF]. 
    )

[2] => Array
    (
        [0] => 08001
        [SQLSTATE] => 08001
        [1] => -1
        [code] => -1
        [2] => [unixODBC][Microsoft][ODBC Driver 17 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.
        [message] => [unixODBC][Microsoft][ODBC Driver 17 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.
    )

0 个答案:

没有答案