【问题标题】:How to connect in MS sql server using php如何使用 php 在 MS sql server 中连接
【发布时间】:2017-06-21 08:30:33
【问题描述】:

如何使用php连接到sql server?

$server = "MySQLSERVER";

$conn = mysqli_connect($server,'sa','11111111');

if (!$conn) 
{
    die("Something went wrong while connecting to MSSQL");
}

这段代码给出了结果:

警告:mysqli_connect(): (HY000/1130): Host 'kpadilla.rafi.local' is 不允许连接到这个 MariaDB 服务器 D:\xampp\htdocs\sample\sample.php 第 5 行

【问题讨论】:

  • 您是否尝试过使用名为 Google 的 famos 工具?
  • 我认为kpadilla.rafi.local不允许连接...
  • MariaDB 与 MicroSoft SQL Server 关系不大...
  • 首先,$server 应该是 localhost - 而不是 MySQLSERVER。此外,mysqli_connect 需要 4 个参数,而不是 3 个。第一个是 sql 服务器(通常是 localhost - 如果您确定使用 xampp localhost),第二个是用户,第三个是密码,第四个(缺少您的代码)是数据库的名称。 php.net/manual/de/mysqli.quickstart.connections.php

标签: php sql-server


【解决方案1】:

您必须使用mssql_connect 函数而不是mysqli_connect,因为您尝试连接MSSQL Server。 (先安装mssql扩展:http://php.net/manual/en/mssql.installation.php

$conn = mssql_connect($server,'sa','11111111');

if (!$conn) 
{
    die("Something went wrong while connecting to MSSQL");
}

【讨论】:

    【解决方案2】:

    你应该使用 mssql_connect:

    http://php.net/manual/de/function.mssql-connect.php

    $conn = mssql_connect($server, $user, $password);
    

    【讨论】:

      猜你喜欢
      • 2013-05-27
      • 1970-01-01
      • 2017-01-29
      • 1970-01-01
      • 2010-11-08
      • 1970-01-01
      • 2014-02-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多