title: mysql_result conversion to sqlsrv
body: <p>I'm just starting to learn PHP and I'm having difficulty converting mysql_result to something that uses sqlsrv.</p>
  
  <p>The code I'm trying to convert is:
  (edited to include the full code)</p>
  
  <pre><code> function database($querydb) {
  
  global $global;
  global $field;
  
  if (isset($global['queries'])) {
      $global['queries']++;
  } else {
      $global['queries'] = "1";
  }
  $field['queries'] = $global['queries'];
  if (isset($global['query_log'])) {
      $global['query_log'] .= "\n&lt;br&gt;$querydb";
  } else {
      $global['query_log'] = "$querydb";
  }
  
  $serverName = "XXX";
  $uid = "XXX";
  $pwd = "XXX";
  $dbName = "XXX";
  
  
  $connectionInfo = array("UID" =&gt; $uid, "PWD" =&gt; $pwd, "Database" =&gt; $dbName, "ReturnDatesAsStrings"=&gt;true);
  
  $conn = sqlsrv_connect($serverName, $connectionInfo);
  
  $stmt = sqlsrv_query($conn, $querydb) or return_error("Query Error: $querydb");
  
      while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC) ) 
          {
          $global['dbresult'] = $row;
          }
  
  
  if ((substr($querydb,0,6)!="INSERT") &amp;&amp; (substr($querydb,0,6)!="UPDATE") &amp;&amp; (substr($querydb,0,6)!="DELETE")) {
  
  while ($row1 = sqlsrv_fetch_array($stmt))
  {
  $global['dbnumber'] = mysql_numrows($global['dbresult']);  // original $dbnumber
  }
  
  return;
  
  }
  
  function return_error($error) {
  print $error;
  exit;
  }
  
  function date_status($date, $username) {
  
  global $global;
  global $field;
  global $input;
  global $text;
  
  $status = "0";
  
  if ($username!="") {
  
      $query = "SELECT countedrow.total, id, start_date, end_date FROM calendar JOIN (SELECT total = COUNT(*) FROM oc_calendar) AS countedrow ON 1=1";
  
      database($query);
  
  
      for ($i = 0; $i &lt; $global['dbnumber']; $i++) {
  
          $status = "1";
  
          $event_id = sqlsrv_fetch_array($global['dbresult'],$i,"id"); 
  
  
      }
  }
  
  return $status;
  
  }
  </code></pre>
  
  <p>I have tried sqlsrv_get_field, sqlsrv_fetch, sqlsrv_fetch_array but I'm obviously not getting the syntax right and missunderstanding this as I'm getting an error of:</p>
  
  <blockquote>
    <p>sqlsrv_fetch_array() expects parameter 1 to be resource, array given in...</p>
  </blockquote>
  
  <p>... with what ever I do.</p>
  
  <p>How do I extract the id from the array to set $event_id ? Where am I going wrong?</p>