0

我正在使用 Xampp 和 Php 5.4 (Zend studio) 并下载 sqlserver driver download V3.0 for php 5.4

我跟着这个网址

我配置了 URL 上面的所有步骤,但仍然无法打开连接并且出现错误..

Connection could not be established.

Array ( [0] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 53 [code] => 53 [2] => [Microsoft][SQL Server Native Client 11.0]Named Pipes Provider: Could not open a connection to SQL Server [53]. [message] => [Microsoft][SQL Server Native Client 11.0]Named Pipes Provider: Could not open a connection to SQL Server [53]. ) [1] => Array ( [0] => HYT00 [SQLSTATE] => HYT00 [1] => 0 [code] => 0 [2] => [Microsoft][SQL Server Native Client 11.0]Login timeout expired [message] => [Microsoft][SQL Server Native Client 11.0]Login timeout expired ) [2] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 53 [code] => 53 [2] => [Microsoft][SQL Server Native Client 11.0]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] => [Microsoft][SQL Server Native Client 11.0]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 enter code here and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. ))

请针对上述问题给出解决方案。

4

2 回答 2

0

转到开始\Microsoft SQL Server 2008\配置工具\SQL Server 配置管理器,然后是SQL Native Client Configuration、Client Protocols 并检查是否启用了共享内存、tcp/ip 和命名管道。

我写这个作为答案,因为我还不能评论。

于 2013-07-24T11:10:52.923 回答
0

(并不是要复活一个旧帖子,但以防万一其他人正在寻找答案,并且因为这个帖子是在我搜索时出现的......)

使用本机驱动程序从 XAMPP 上的 PHP 连接到 SQL_server 的简短分步指南:

  1. 首先从http://www.microsoft.com/en-us/download/details.aspx?id=20098下载 PHP for SQL_server Microsoft 本机驱动程序请注意选择适合您设置的驱动程序。

  2. 将它安装到 PHP 扩展目录(通常在 中c:\xampp\php\ext)。

  3. 通过取消注释或附加该行(取决于选择的驱动程序版本)在PHP.ini(通常在)中配置新扩展。C:\xampp\phpIE:

    extension = php_sqlsrv_55_ts.dll
    
  4. 从 XAMPP 控制面板重新启动 Apache(停止 + 启动)。

    现在您的 PHP 设置能够连接到 SQL_server 数据库。修改以下代码以使用您自己的数据库对其进行测试:

    <?php
    $server = "SERVER\SQLEXPRESS";
    $database = "test_database";
    $user = "test_user";
    $pwd = "test_password";
    
    $options = array(  "UID" => $user,  "PWD" => $pwd,  "Database" => $database);
    $conn = sqlsrv_connect($server, $options);
    
    if ($conn === false) {
        die("<pre>".print_r(sqlsrv_errors(), true));
    }
    echo "Successfully connected!";
    
    $sql = "SELECT TOP 50 * FROM dbo.table_name";
    $query = sqlsrv_query($conn, $sql);
    if ($query === false) {
        exit("<pre>".print_r(sqlsrv_errors(), true));
    }
    
    while ($row = sqlsrv_fetch_array($query))  {
        echo "<p>$row[field1] $row[field2]</p>";
    }
    
    sqlsrv_free_stmt($query);
    sqlsrv_close($conn);
    

在 SQL_server 2008 R2 和 SQL_server 2014 express 上从 XAMPP 3.2.1 和 XAMPP 5.6.14 测试。

于 2016-04-07T15:25:42.180 回答