CodeIgniter Forums

Full Version: How to handle DECLARE and SET in MS SQL query with ODBC driver?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
Try using odbc_next_result() to loop thru the result sets?