title: PHP sqlsrv_query() expects parameter 1 to be resource, boolean given in
body: <p>I am New with MS-SQL with PHP.
  I am trying to save the session to database but in MS-SQL.
  when i run the php i get the error.</p>
  <blockquote>
  <p>sqlsrv_query() expects parameter 1 to be resource, boolean.</p>
  </blockquote>
  <p>This is my Code.</p>
  <pre><code>&lt;?php
  class SQLSrv_Session
  {
  const DB_HOST= &quot;1DB_HOST&quot;;
  const DB_PASS= &quot;DB_PASS&quot;;
  const DB_USER= &quot;DB_USER&quot;;
  const DB_NAME= &quot;DB_NAME&quot;;
  const DB_SESSION_TABLE=&quot;DB_SESSION_TABLE&quot;;
  /**
   * Database connection resource
   * 
   * @var resource
   */
  private static $_sess_db;
  /**
   * Escape string for mssql query
   * 
   * @param string $data
   * @return string
   */
  private static function sqlsrv_escape($data) {
      return str_replace(&quot;'&quot;,&quot;''&quot;,$data);
  }
  /**
   * Open the session
   * 
   * @return bool
   */
  public static function open() {
      $connectionInfo= array (
                          'UID' =&gt; self::DB_USER,
                          'PWD' =&gt; self::DB_PASS,
                          'Database' =&gt; self::DB_NAME
                          );
      self::$_sess_db = sqlsrv_connect(self::DB_HOST,$connectionInfo);
      return self::$_sess_db;
  }
  /**
   * Close the session
   * 
   * @return boolean
   */
  public static function close() {
      return sqlsrv_close(self::$_sess_db);
  }
  /**
   * Read the session
   * 
   * @param string $id
   * @return string 
   */
  public static function read($id) {
      $sql = 'SELECT SCS_DATA FROM '. self::DB_SESSION_TABLE .' '.
             'WHERE SCS_ID = \''.self::sqlsrv_escape($id).'\'';       
      $stmt= sqlsrv_query(self::$_sess_db, $sql);
      if (!empty($stmt)) {
          $row= sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC);
          return $row['SCS_DATA'];
      }
      return '';
  }
  /**
   * Write the session
   * 
   * @param string $id
   * @param string $value
   * @return boolean
   */
  public static function write($id, $value) {
  
  echo 'aaaaaaa';
      $sql= 'UPDATE '.self::DB_SESSION_TABLE.' SET SCS_DATA=?,SCS_ACCESS=? WHERE SCS_ID=?';         
      $params = array(111112, 3333322, 12222221);     
      $stmt= sqlsrv_query(self::$_sess_db, $sql, $params);
  print_r($params);
      if (!empty($stmt)) {
          $result= sqlsrv_rows_affected($stmt);
          if ($result&gt;0) {
          echo 'eeew';
              return true;
          }else{
          echo $result;
          }
      }
      $sql= 'INSERT INTO '.self::DB_SESSION_TABLE.' (SCS_DATA,SCS_ACCESS, SCS_ID) VALUES (?,?,?)';
      $stmt= sqlsrv_query(self::$_sess_db, $sql, $params);
   print_r($params);
  
      if (!empty($stmt)) {
          $result= sqlsrv_rows_affected($stmt);
          if ($result&gt;0) {
              return true;
              echo 'yyyyyy';
          }else{
          echo $result;
          }
      }
      return false;
  }
  /**
   * Destroy the session
   * 
   * @param string $id
   * @return boolean
   */
  public static function destroy($id) {
      $sql = 'DELETE FROM '.self::DB_SESSION_TABLE.' WHERE SCS_ID = ?';
      $params= array(self::sqlsrv_escape($id)); 
      $stmt= sqlsrv_query(self::$_sess_db,$sql,$params);
      return ($stmt!==false);
     }
     /**
   * Garbage Collector
   * 
   * @param integer $max
   * @return boolean
   */
  public static function gc($max) {
      $sql = 'DELETE FROM '.self::DB_SESSION_TABLE.' WHERE SCS_ACCESS &lt; ?';
      $params= array(array(date(&quot;Y-m-d H:i:s&quot;,time() - $max))); 
      $stmt= sqlsrv_query(self::$_sess_db, $sql, $params);
      return ($stmt!==false);
     }
  }
  
  // to prevent problem of session write after close as PHP 5.0.5 
   register_shutdown_function('session_write_close');
  
  ini_set('session.save_handler', 'user');
  session_set_save_handler(array('SQLSrv_Session', 'open'),
                       array('SQLSrv_Session', 'close'),
                       array('SQLSrv_Session', 'read'),
                       array('SQLSrv_Session', 'write'),
                       array('SQLSrv_Session', 'destroy'),
                       array('SQLSrv_Session', 'gc'));
                       
                       
                       // display PHP error
  error_reporting(E_ALL);
  ini_set(&quot;display_errors&quot;, 1);
  
  // set the probability of garbage collector to 1
  ini_set('session.gc_probability', 100);
  ini_set('session.gc_divisor', 100);
  
  session_start();
  
  $_SESSION  ['lll']= 'pppp';
  </code></pre>
  <p>I am getting the error in line 55,121,74,86,44.</p>
  <p>this are the lines with the error.</p>
  <blockquote>
  <p>$stmt= sqlsrv_query(self::$_sess_db, $sql);</p>
  <p>$stmt= sqlsrv_query(self::$_sess_db, $sql,$params);</p>
  <p>$stmt= sqlsrv_query(self::$_sess_db, $sql, $params);</p>
  <p>$stmt= sqlsrv_query(self::$_sess_db, $sql,$params);</p>
  <p>sqlsrv_close(self::$_sess_db);</p>
  </blockquote>
  <p>If some one please can find wirer the error is the the sqlsrv_query.
  Thanks</p>