php无法打开sqlserver 2000数据库

时间:2010-03-19 06:22:21

标签: php sql-server

我可以使用sql server management studio打开sqlserver 2000数据库,

但我无法使用相同的用户名和密码在php页面中打开相同的数据库。

问题是什么?

if(!$dbSource->open("192.168.4.241:1433","sa","sa","NorthWind"))
{
    echo  "Fail to open the sql server 2000 database";
}

-----------------------

  function open($db_server, $db_user, $db_password, $db_name) 
  {

    $this->conn = mssql_connect($db_server, $db_user, $db_password);
    if(!$this->conn)
    {
        return false;
    }
    @mssql_select_db($db_name, $this->conn);
    return true;
  }

1 个答案:

答案 0 :(得分:0)

mssql_get_last_message()告诉您问题所在。

  function open($db_server, $db_user, $db_password, $db_name)
  {
    $this->conn = mssql_connect($db_server, $db_user, $db_password);
    if(!$this->conn)
    {
      echo '<pre>Debug: mssql_connect failed, reason: ', htmlspecialchars(mssql_get_last_message()), '</pre>';
      return false;
    }
    if ( false===@mssql_select_db($db_name, $this->conn) ) {
      echo '<pre>Debug: mssql_select_db failed, reason: ', htmlspecialchars(mssql_get_last_message()), '</pre>';
      return false;
    }
    return true;
  }

另见:mssql_min_error_severity()