php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10843 Function creates new array but does not reset pointer
Submitted: 2001-05-13 23:03 UTC Modified: 2002-05-21 22:56 UTC
From: peter at petermoulding dot com Assigned:
Status: Closed Package: ODBC related
PHP Version: 4.0.5 OS: NT 4.0 sp6
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: peter at petermoulding dot com
New email:
PHP Version: OS:

 

 [2001-05-13 23:03 UTC] peter at petermoulding dot com
I tried odbc_fetch_into() in the enclosed loop. I had to inset the reset($array) to get the loop working. I figure the function is creating new content in the array but not resetting the array pointer back to the beginning. The function should either
1/ add to the end of the array and increment the pointer
or
2/ replace the contents and reset the pointer.

$sql = "select * from stock";
$result = odbc_exec($connection["vitamins"], $sql);
if($result)
   {
   print("<br>Result from odbc_fetch_into()" );
   $array = "";
   while($result_all = odbc_fetch_into($result, 0, $array))
      {
      reset($array);
      print("<br>" );
      while(list($k, $v) = each($array))
         {
         print($v . "&nbsp;&nbsp;");
         }
      }
   }
else
   {
   print("<br>No result" );
   }

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-01 11:57 UTC] kalowsky@php.net
what database is this with?
 [2001-06-01 13:48 UTC] peter at petermoulding dot com
The database happened to be Access. I have MySQL and PostgeSQL available through ODBC and MySQL direct. I though the action to odbc_fetch_into() would be the same no matter which database.

Normally when a function returns an array, the pointer is at the start. Perhaps this is the result of passing an array by reference and what is needed is a documentation change to highlight what happens to the pointer.
 [2001-06-11 11:03 UTC] kalowsky@php.net
can you please try this patch with a current build of PHP?

Index: php_odbc.c
===================================================================
RCS file: /repository/php4/ext/odbc/php_odbc.c,v
retrieving revision 1.92
diff -u -r1.92 php_odbc.c
--- php_odbc.c  11 Jun 2001 01:00:43 -0000      1.92
+++ php_odbc.c  11 Jun 2001 15:04:36 -0000
@@ -1489,6 +1489,9 @@
                }
                zend_hash_index_update((*pv_res_arr)->value.ht, i, &tmp, sizeof(pval *), NULL);
        }
+
+       zend_hash_internal_pointer_reset((*pv_res_arr)->value.ht);
+
        if (buf) efree(buf);
        RETURN_LONG(result->numcols);
 }

 [2001-06-11 22:35 UTC] kalowsky@php.net
comment from user:

That patch is all Greek to me. I will have to find a 
compiler and learn how to
compile. Is there any chance of putting it in the 
updates at php4win or www.zend.com/snapshots

php4win posted an update 4.0.7 2001-06-11 so I tested that 
and still same
problem. 4.0.7 produced a strange result. The 
code:
while($result_all = odbc_fetch_into($result, 0, $array))
produces:
Fatal error: Only variables can be passed by reference

The following works:
$zero = 0;
while($result_all = odbc_fetch_into($result, $zero, 
$array))

$zero remains at 0 so is not updated.
 [2002-05-21 22:56 UTC] kalowsky@php.net
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at 
http://www.php.net/downloads.php


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon May 05 18:01:29 2025 UTC