php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48057 Only the date fields of the first row are fetched, others are empty
Submitted: 2009-04-23 07:26 UTC Modified: 2009-07-20 00:18 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: info at programmiernutte dot net Assigned:
Status: Closed Package: PDO related
PHP Version: 5.2, 5.3, HEAD OS: *
Private report: No CVE-ID: None
 [2009-04-23 07:26 UTC] info at programmiernutte dot net
Description:
------------
PDO::fetch() only returns date fields on the first call. 
subsequent calls return empty strings instead of dates. 

Configure Command =>  './configure'  '--
prefix=/usr/local/php' '--with-apxs2' '--without-pdo-sqlite' 
'--without-mysql'

php.ini-settings don't seem to matter, I only have these:
date.timezone = "Europe/Berlin"
include_path = "/Library/WebServer/php-includes/"
allow_call_time_pass_reference = Off
expose_php = Off
magic_quotes_gpc = Off
register_argc_argv = Off
output_buffering = On
plus settings for xdebug, apc and memcache, I already tried 
disabling them, no difference.

PDO_FIREBIRD is loaded as an 
extension:extension=pdo_firebird.so






Reproduce code:
---------------
isql:
SQL> create database 'test.fdb';
SQL> CREATE TABLE FOO (ID INTEGER, BAR DATE);
SQL> INSERT INTO FOO (ID, BAR) VALUES ('1', '11.04.2009');
SQL> INSERT INTO FOO (ID, BAR) VALUES ('2', '12.04.2009');
SQL> INSERT INTO FOO (ID, BAR) VALUES ('3', '13.04.2009');

php:
<?php
$oPDO = new PDO(     
'firebird:dbname=localhost:test.fdb;charset=ISO8859_1',
        'sysdba',
        'masterkey',
        array(
                PDO::ATTR_PERSISTENT => true,
                PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ
        )
);


$oStmt = $oPDO->query('select id, bar from foo');


foreach($oStmt as $oRow)
{
        var_dump($oRow);
}
?>



Expected result:
----------------
object(stdClass)#3 (2) {
  ["ID"]=>
  string(1) "1"
  ["BAR"]=>
  string(10) "2009-04-11"
}
object(stdClass)#4 (2) {
  ["ID"]=>
  string(1) "2"
  ["BAR"]=>
  string(10) "2009-04-12"
}
object(stdClass)#3 (2) {
  ["ID"]=>
  string(1) "3"
  ["BAR"]=>
  string(10) "2009-04-13"
}






Actual result:
--------------
object(stdClass)#3 (2) {
  ["ID"]=>
  string(1) "1"
  ["BAR"]=>
  string(10) "2009-04-11"
}
object(stdClass)#4 (2) {
  ["ID"]=>
  string(1) "2"
  ["BAR"]=>
  string(0) ""
}
object(stdClass)#3 (2) {
  ["ID"]=>
  string(1) "3"
  ["BAR"]=>
  string(0) ""
}






Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-04-27 17:05 UTC] jani@php.net
Does this happen with PHP 5.2.9 ?
 [2009-05-01 08:29 UTC] info at programmiernutte dot net
Worse, the only row that would be complete is nulled because of an 
older bug:
array(4) {
  ["ID"]=>
  NULL
  [0]=>
  NULL
  ["BAR"]=>
  NULL
  [1]=>
  NULL
}
array(4) {
  ["ID"]=>
  string(1) "2"
  [0]=>
  string(1) "2"
  ["BAR"]=>
  string(0) ""
  [1]=>
  string(0) ""
}
array(4) {
  ["ID"]=>
  string(1) "3"
  [0]=>
  string(1) "3"
  ["BAR"]=>
  string(0) ""
  [1]=>
  string(0) ""
}
 [2009-07-02 23:58 UTC] info at programmiernutte dot net
I dug out my rusty C skills and looked into this myself. It came down 
to the following patch which works for me although I don't quite see 
why this minor change would cause different behaviour. Maybe someone 
would enlighten me.

This is my patch against PHP 5.3.0:

--- php-5.3.0/ext/pdo_firebird/firebird_statement.c     2009-02-09 
13:07:23.000000000 +0100
+++ php-5.3.0patched/ext/pdo_firebird/firebird_statement.c      2009-
07-03 01:41:24.000000000 +0200
@@ -363,7 +363,9 @@ static int firebird_stmt_get_col(pdo_stm
                                                fmt = S->H-
>timestamp_format ? S->H->timestamp_format : PDO_FB_DEF_TIMESTAMP_FMT;
                                        }
                                        /* convert the timestamp into 
a string */
-                                       *ptr = FETCH_BUF(S-
>fetch_buf[colno], char, *len = 80, NULL);
+
+                                       *len = 80;
+                                       *ptr = FETCH_BUF(S-
>fetch_buf[colno], char, *len, NULL);
                                        *len = strftime(*ptr, *len, 
fmt, &t);
                                        break;
                                case SQL_BLOB:
 [2009-07-20 00:17 UTC] svn@php.net
Automatic comment from SVN on behalf of felipe
Log: - Fixed bug #48057 (Only the date fields of the first row are fetched, others are empty)
  patch by: info at programmiernutte dot net

Revision: http://svn.php.net/viewvc?view=revision&revision=284404
 [2009-07-20 00:18 UTC] felipe@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Thanks for the patch!
Fixed in 5.2, 5.3 and HEAD.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC