title: Difference between mssql_connect and sqlsrv_connect
body: <p>I have just changed the connection driver (extension) from <code>mssql_connect</code> to work with <code>sqlsrv_connect</code>. Unfortunately things do not seem to work as I wanted. I'd appreciate if someone can tell me what’s wrong and how can I fix it.</p>
  
  <p>Code excerpt:</p>
  
  <pre><code>//a oracle DB moudle with a generic functions such as 
  //db_connect() db_query()
  
  /// turn on verbose error reporting (15) to see all warnings and errors 
  error_reporting(15);
  //generic DB operations
  
  // Global record . for using in 
  $curr_rec = NULL;
  
  function dbok($res)
  {
      if($res==false){
          echo "DB error: "."FIXME need error mesg"."\n";
          exit;
      }
      return $res;
  }
  
  function db_now_expr()
  {
      return "getdate()";
  }
  
  function db_is_connected($dbh)
  {
      return $dbh&gt;0;
  }
  
  function ensure_connected($dbh)
  {
      if(!db_is_connected($dbh)) die("DB is not connected, operation failed");
      //echo "DEBUG: hdb=$dbh"; 
  }
  
  //connect to given database 
  //return handler to DB
  
  
  function dbo_logon($dbserver,$dbname)
  {
  
      $tsql = ??????? ====&gt;&gt;&gt; what should i put here???? 
  
      $dbserver = "computername\SQLEXPRESS";
      $dbname = MY_Database_name;
  
      $connectionOptions = array("Database"=&gt;"BULL");
  
      $dbh=dbok(sqlsrv_connect($dbserver, $connectionOptions));
      dbok(sqlsrv_query($dbname,$dbh)); 
  
      $stmt = sqlsrv_query( $connectionOptions, $tsql );
  
      return $dbh;
  
  }
  
  //close DB
  function dbo_logoff($dbh)
  {
      if(!db_is_connected($dbh)) echo("DB disconnect error");
      sqlsrv_close($dbh);
  }
  </code></pre>
  
  <p>Here is the original code using <code>mssql_connect</code>:</p>
  
  <pre><code>//a oracle DB module with a generic function such as 
  //db_connect() db_query()
  
  /// turn on verbose error reporting (15) to see all warnings and errors 
  error_reporting(15);
  //generic DB operations
  
  // Global record . for using in 
  $curr_rec = NULL;
  
  function dbok($res)
  {
      if($res==false){
          echo "DB error: "."FIXME need error mesg"."\n";
          exit;
      }
      return $res;
  }
  
  function db_now_expr()
  {
      return "getdate()";
  }
  
  function db_is_connected($dbh)
  {
      return $dbh&gt;0;
  }
  
  function ensure_connected($dbh)
  {
      if(!db_is_connected($dbh)) die("DB is not connected, operation failed");
      //echo "DEBUG: hdb=$dbh"; 
  }
  
  //connect to given database 
  //return handler to DB
  function dbo_logon($dbserver,$dbuser,$dbpass,$dbname)
  {
      // $dbh=dbok(mssql_pconnect($dbserver,$dbuser,$dbpass));
      $dbh=dbok(mssql_connect($dbserver,$dbuser,$dbpass));
      //error_log("connect to [$dbname]".date("His")." \r\n",3,"/tmpbull.log"); //DBEUG DELME
      dbok(mssql_select_db($dbname,$dbh));
      //dbo_exec($dbh,"alter session set NLS_DATE_FORMAT='dd-mm-yyyy //hh24:mi:ss'");
      return $dbh;
  
  }
  
  //close DB
  function dbo_logoff($dbh)
  {
      if(!db_is_connected($dbh)) echo("DB disconnect error");
      mssql_close($dbh);
  }
  </code></pre>
  
  <p>Note that I had to change the authentication method from SQL authentication to Windows authentication because <code>sqlsrv_connect</code> uses Windows authentication instead of SQL authentication. Is that right?</p>