php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33689 query() execute() and fetch() all return false on valid select queries
Submitted: 2005-07-14 03:49 UTC Modified: 2005-07-14 04:21 UTC
From: james at safesearching dot com Assigned:
Status: Closed Package: PDO related
PHP Version: 5CVS-2005-07-14 (dev) OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: james at safesearching dot com
New email:
PHP Version: OS:

 

 [2005-07-14 03:49 UTC] james at safesearching dot com
Description:
------------
The code below works fine in 5.1.0b2 for me. In 5.1.0b3 and CVS, however, the code produces an error and segfaults.

In b3/CVS the table is created and the value is inserted.

$db->query('SELECT * FROM foo') returns false and causes the invalid argument error.

$stmt->execute() returns false.

Accessing $stmt->getColumnMeta() causes a segfault.

Throwing a $stmt->fetch() between execute() and getColumnMeta() produces the correct results. (but query() obviously still returns false)

Reproduce code:
---------------
header('Content-type: text/plain');

$db = new PDO('mysql:dbname=test;host=localhost','**','**');

$db->query('CREATE TABLE `foo` ( `bar` INT NOT NULL );');
$db->query('INSERT INTO foo VALUES(1)');

var_dump($db->query('SELECT * FROM foo'));

foreach ($db->query('SELECT * FROM foo') as $row) {
        print_r($row);
}

$stmt = $db->prepare('SELECT * FROM foo');
$stmt->execute();

print_r($stmt->getColumnMeta(0));

Expected result:
----------------
object(PDOStatement)#2 (1) {
  ["queryString"]=>
  string(17) "SELECT * FROM foo"
}
Array
(
    [bar] => 1
    [0] => 1
)
Array
(
    [native_type] => LONG
    [flags] => Array
        (
            [0] => not_null
        )

    [name] => bar
    [len] => 11
    [precision] => 0
    [pdo_type] => 2
)

Actual result:
--------------
bool(false)

Warning:  Invalid argument supplied for foreach() in test.php on line 10

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1024 (LWP 8530)]
zif_PDOStatement_getColumnMeta (ht=1, return_value=0x8173554,
    return_value_ptr=0x0, this_ptr=0x816e6fc, return_value_used=1)
    at /home/james/php5-200507140030/ext/pdo/pdo_stmt.c:1550
1550            add_assoc_string(return_value, "name", col->name, 1);
(gdb) bt
#0  zif_PDOStatement_getColumnMeta (ht=1, return_value=0x8173554,
    return_value_ptr=0x0, this_ptr=0x816e6fc, return_value_used=1)
    at /home/james/php5-200507140030/ext/pdo/pdo_stmt.c:1550
#1  0x404e2e30 in zend_do_fcall_common_helper_SPEC (execute_data=0xbfffc9d0)
    at /home/james/php5-200507140030/Zend/zend_vm_execute.h:184
#2  0x404e2a59 in execute (op_array=0x816e534)
    at /home/james/php5-200507140030/Zend/zend_vm_execute.h:87
#3  0x404c576c in zend_execute_scripts (type=8, retval=0x0, file_count=3)
    at /home/james/php5-200507140030/Zend/zend.c:1087
#4  0x404956ce in php_execute_script (primary_file=0xbfffed30)
    at /home/james/php5-200507140030/main/main.c:1672
#5  0x40558eee in apache_php_module_main (r=0x8160f78, display_source_mode=0)
    at /home/james/php5-200507140030/sapi/apache/sapi_apache.c:53
#6  0x405598e0 in send_php (r=0x8160f78, display_source_mode=0, filename=0x0)
    at /home/james/php5-200507140030/sapi/apache/mod_php5.c:643
#7  0x4055992e in send_parsed_php (r=0x8160f78)
    at /home/james/php5-200507140030/sapi/apache/mod_php5.c:658
#8  0x0805480d in ap_invoke_handler ()
#9  0x08067b0c in process_request_internal ()
#10 0x08067b83 in ap_process_request ()
#11 0x0805fc97 in child_main ()
#12 0x0805fe3a in make_child ()
#13 0x0805ff7d in startup_children ()
#14 0x080605d0 in standalone_main ()
#15 0x08060ed3 in main ()
#16 0x42017589 in __libc_start_main () from /lib/i686/libc.so.6

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-14 04:21 UTC] wez@php.net
This bug has been fixed in CVS.

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 report.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 10:01:29 2024 UTC