tags:

views:

33

answers:

1

I can use the sql server management studio to open a sqlserver 2000 database,

but I can not open the same database in a php page using the same user and password.

what is the problem?

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;
  }
A: 

Let mssql_get_last_message() tell you what the problem is.

  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;
  }

see also: mssql_min_error_severity()

VolkerK
Thank you. I use ODBC to connect sql server successfully. But the mssql_connect() still does not work, and it shows none error message, just blank white page.
Mike108
"blank white page" _could_ mean parse error
VolkerK
Thank you. I set the php.ini secure_connection to Off, and solve the problem.
Mike108