• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to handle DECLARE and SET in MS SQL query with ODBC driver?

#1
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.
Reply

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.