CodeIgniter Forums
How to handle DECLARE and SET in MS SQL query with ODBC driver? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: How to handle DECLARE and SET in MS SQL query with ODBC driver? (/thread-70076.html)



How to handle DECLARE and SET in MS SQL query with ODBC driver? - 90zlaya - 02-16-2018

Hello everyone! I have problem running MS SQL queries in CodeIgniter.

If we have query like this:


PHP Code:
$return '';

 
  $query "
       DECLARE @number int
       DECLARE @name varchar(10)

       SET @number = 1000
       SET @name = 'nothing'
       
       SELECT @number AS one_thousand, @name AS nothing
   "
;
 
  $result $this->mssql_connect->query($query);
 
  $sql $result->result_array();
 
  foreach ($sql as $row)
 
  {
 
      $return .= $row['one_thousand'];
 
      $return .= ' ';
 
      $return .= $row['nothing'];
 
      $return .= '<br/>';
 
  }
 
  
   
return $return

Following error occurs:

Quote:   odbc_fetch_array(): No tuples available at this result index

Do I have special methods for ODBC type queries? My current fix for this problem is to split query string and insert PHP variable, which is ugly and requires a lot of work in form of redefinition of existing queries.


RE: How to handle DECLARE and SET in MS SQL query with ODBC driver? - emmanuel - 02-19-2018

Try using odbc_next_result() to loop thru the result sets?