Switching fromMySQL to ODBC


I wrote an Application using WAMP. For some reason I have to use ODBC now.

I defined a class with the following method:

function select ($sql="")
     $count = 0;
     $data = array();
     while ( $row = mysql_fetch_array($results))
          $data[$count] = $row;
     return $data;

Since the lack of a function like "odbc_fetch_array()" I need a different way to return an associative array with "return $data", because the above method is the basis for a lot of other application-specific methods.

Any suggestions?

Who is Participating?
axis_imgConnect With a Mentor Commented:
What version of PHP are you using? There is a function called odbc_fetch_array(), although I know it has had problems in early versions of PHP4.

I am not all that familiar with the odbc modules, but just from glancing at the docs, it seems that other users tend to use odbc_fetch_into($res, &$result_array) to throw it into the array. ie: while(odbc_fetch_into($res, &$array))

The corresponding pages can be found at:
[the 2nd example seems to be what you need]


The odbc functions seem to be poorly written in my opinion, as there are many different variations on how to write it based on the exact version of PHP you are using.

Anyway... please let me know if you have any more questions.
jufabw00Author Commented:
... works with 4.2.1 (doesn't with 4.0.6. - yet ;-)))

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.