【问题标题】:how to connect to remote mssql using php如何使用php连接到远程mssql
【发布时间】:2015-12-30 02:36:14
【问题描述】:

我可以从终端使用 tsql 很好地连接到远程 mssql,但我无法从 php 连接到服务器。 我安装了freeTds,unixODBC并在freetds.conf中设置了配置

已尝试连接代码

  $myServer = "x.xx.xxx.xxx";
$myUser = "testuser";
$myPass = "testpwd";
$myDB = "Testdb"; 

 //connection to the database
  mssql_connect($myServer, $myUser, $myPass);
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
  or die("Couldn't connect to SQL Server on $myServer");

我收到 500 内部错误,谁能指导我如何从 php 连接到远程 mssql 服务器。

【问题讨论】:

  • 您是否重新编译了 PHP 和/或加载了 MSSQL 模块? php.net/manual/en/mssql.installation.php
  • 能否包含您从日志中获得的 500 错误消息?然后我们也许可以缩小问题的范围。 Rob 的建议首先要检查一下。

标签: php sql-server odbc freetds


【解决方案1】:

试试这个: (如果远程使用 ip 而不是 localhost)。

PHP

   <?php

    $myServer = "localhost";
    $myUser = "testuser";
    $myPass = "testpwd";
    $myDB = "Testdb";

    @mysql_connect("$myServer ","$myUser","$myPass") or die ("could not connect to MySQL");
    @mysql_select_db("$myDB") or die ("No database");

    echo "sucess";

    ?>

【讨论】:

  • 很确定 mysql 函数不会在 SQL Server 上工作 :)
猜你喜欢
  • 2015-06-24
  • 1970-01-01
  • 1970-01-01
  • 2015-01-15
  • 2019-01-11
  • 1970-01-01
  • 2017-09-27
  • 2014-06-28
  • 1970-01-01
相关资源
最近更新 更多