From:             blackmagic at computer dot org
Operating system: Centos 5.3
PHP version:      5.2.9
PHP Bug Type:     PostgreSQL related
Bug description:  implode giving wrong results

Description:
------------
A Postgresql query returns an array. If the array is imploded each 
value in the original array appears twice in the implosion.

Assume a Postgresql result array contains $array[0], $array[1], 
$array[2]; 
$x=implode ('|', $array) puts
$array[0]|$array[0]|$array[1]|$array[1]|$array[2]|$array[2] into $x.
$x=$array[0]. '|' . $array[1]. '|' . $array[2]; works fine.
Why is there a difference?

Reproduce code:
---------------
<?php
$company;                                                                 
                        $details;                                          
                                                $index;                    
                                                             
require_once('../functions/sql_functions.inc');                           
                        database_connect();                                
                                               $db_query = "SELECT * FROM
company ORDER BY id ";
database_query(__FILE__, __LINE__);                                       
                    if ($db_rows == 0) echo $DB_EMPTY_FILE;                
                                                                           
                         
else {
for ($index=0; $index<$db_rows; $index++) {                               
                                         $details =
pg_fetch_array($db_result, $index);                                        
             $company[$index] = implode('|', $details); }   //THE BUG IS
HERE//                                                     $details =
implode('^', $company);                                                    
              echo "$details"; }                                           
                                                                           
                             


Expected result:
----------------
I expected to see:
$company[$index] = $details[0]|$details[1]|$details[2].




Actual result:
--------------
Actual result:
$company[$index] = 
$details[0]|$details[0]|$details[1]|$details[1]|$details[2]|$details[
2].

This program was working fine until I changed 
$company[$index] = $details[0]. '|' . $details[1]. '|' . $details[2];
to
$company[$index] = implode('|', $details);




-- 
Edit bug report at http://bugs.php.net/?id=48015&edit=1
-- 
Try a CVS snapshot (PHP 5.2):        
http://bugs.php.net/fix.php?id=48015&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):        
http://bugs.php.net/fix.php?id=48015&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):        
http://bugs.php.net/fix.php?id=48015&r=trysnapshot60
Fixed in CVS:                        
http://bugs.php.net/fix.php?id=48015&r=fixedcvs
Fixed in CVS and need be documented: 
http://bugs.php.net/fix.php?id=48015&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=48015&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=48015&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=48015&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=48015&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=48015&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=48015&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=48015&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=48015&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=48015&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=48015&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=48015&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=48015&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=48015&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=48015&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=48015&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=48015&r=mysqlcfg

Reply via email to