From:             [EMAIL PROTECTED]
Operating system: NT 4.0 Workstation - SP6
PHP version:      4.0.6
PHP Bug Type:     ODBC related
Bug description:  odbc_fetch_into using an array in an object

While working on a class to encapsulate ODBC functionality, I discovered a
problem in calling odbc_fetch_into with an array that exists inside a
class. I was creating an array in the class to hold the results of the
current row, and allowing the user of the class to reference the fields
from there. It looked a little like this:

class DB {
var $record = array();
var $queryid;
...
 function fetch_row() {
  return(odbc_fetch_into($this->queryid, $this->record)
 }
...
}

When I tried to display the results from $record with something like echo
$myDB->record[0];, all that is displayed is "Array[0]" (w/o quotes).

After some tinkering, I modified the "fetch_row()" function in my class to
accept an array parameter:
function fetch_row($myarray) {
return(odbc_fetch_into($this->queryid, $myarray)
}

This corrected the problem, although I have to give up my encapsulation.
Now echo $myarray[0]; displays the appropriate data.

So it appears that there is a conflict with encapsulated arrays and
odbc_fetch_into. I believe that there was a similiar problem with the MS
SQL extension a while back (mid version 3 around 3.0.12 or so).

I'm accessing an MS Access 97 database through Microsoft's ODBC driver. 

A fully functional example follows.

Greg Sohl
Cedar Rapids, IA


Here is a fully functional example of what works and what doesn't work. Its
as short as I could get it and keep it understandable.

<html><body>
<table border="1">
<tr><td>ID</td><td>Name</td><td>Email</td></tr>
<?
// For testing simple array encapsulation
class Results
        {
        var $record = array();
        }

$dblink = odbc_connect('ftp_reg', '', '');
$queryid = odbc_exec($dblink, "select * from Test");    // 3 columns

/* This technique works - Calling odbc_fetch_into with a global array */
$my_array = array();
while(odbc_fetch_into($queryid, $my_array))
        echo
"<tr><td>$my_array[0]</td><td>$my_array[1]</td><td>$my_array[2]</td></tr>";

odbc_fetch_row($queryid, 0);    // Reset to the begininning

/* This technique does not work - Calling odbc_fetch_into with an array in
a class */
$my_results = new Results();
while(odbc_fetch_into($queryid, $my_results->record))
        echo
"<tr><td>$my_results->record[0]</td><td>$my_results->record[1]</td><td>$my_results->record[2]</td></tr>";

?>
</table></body></html>
-- 
Edit bug report at: http://bugs.php.net/?id=14238&edit=1


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to