php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14238 odbc_fetch_into using an array in an object
Submitted: 2001-11-26 12:25 UTC Modified: 2002-05-13 18:48 UTC
From: gsohl at freedomgroup dot com Assigned:
Status: Not a bug Package: ODBC related
PHP Version: 4.0.6 OS: NT 4.0 Workstation - SP6
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: gsohl at freedomgroup dot com
New email:
PHP Version: OS:

 

 [2001-11-26 12:25 UTC] gsohl at freedomgroup dot com
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>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-05-13 18:48 UTC] kalowsky@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately your version of PHP is too old -- the problem
might already be fixed. Please download a new PHP
version from http://www.php.net/downloads.php

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 11:01:29 2024 UTC