|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2005-03-27 16:10 UTC] lmpmbernardo at users dot sourceforge dot net
 Description:
------------
Using most recent PDO (0.3) and PDO_MYSQL (0.2).
Configuration: './configure' '--with-apxs2=/usr/local/apache2/bin/apxs' '--with-mysql=/usr/local/mysql4/' '--with-mysqli=/usr/local/mysql4/bin/mysql_config' '--with-xmlrpc' '--with-zlib'
Problem: calling PDO::lastInsertId() causes segmentation fault.
Reproduce code:
---------------
$db = new PDO("mysql:dbname=test;host=127.0.0.1", "root", "");
echo "Successfully created a PDO object";
$db->setAttribute(PDO_ATTR_ERRMODE, PDO_ERRMODE_EXCEPTION);
try {
    $sql = "CREATE TABLE pdobomb(id INT(11) NOT NULL auto_increment, name VARCHAR(20), PRIMARY KEY (id))";
    $db->query($sql);
} catch(Exception $e) {
    // ok; db created before...
}
$name = "XXXXXX";
$sql = "INSERT INTO pdobomb(id, name) VALUES(null, '$name')";
$db->query($sql);
$id = $db->lastInsertId(); // offending call
echo $id;
Expected result:
----------------
Expect: no segmentation fault; output of last inserted id.
Actual result:
--------------
I was not succesfull in compiling PDO with the debug switch. Not sure why... In any case below is a backtrace that may be of use.
[lmpmbernardo@antonio tmp]$ php -v
PHP 5.1.0-dev (cli) (built: Mar 27 2005 13:27:38)
Copyright (c) 1997-2005 The PHP Group
Zend Engine v2.1.0-dev, Copyright (c) 1998-2004 Zend Technologies
    with Xdebug v2.0.0beta2, Copyright (c) 2002, 2003, 2004, by Derick Rethans
[lmpmbernardo@antonio tmp]$ cat /home/lmpmbernardo/workspace/pdotest/pdodebug.php
<?php
 
$db = new PDO("mysql:dbname=test;host=127.0.0.1", "root", "");
echo "Successfully created a PDO object";
$db->setAttribute(PDO_ATTR_ERRMODE, PDO_ERRMODE_EXCEPTION);
try {
    $sql = "CREATE TABLE pdobomb(id INT(11) NOT NULL auto_increment, name VARCHAR(20), PRIMARY KEY (id))";
    $db->query($sql);
} catch(Exception $e) {
    // ok; db created before...
}
$name = "XXXXXX";
$sql = "INSERT INTO pdobomb(id, name) VALUES(null, '$name')";
$db->query($sql);
$id = $db->lastInsertId();
echo $id;
 
?>
[lmpmbernardo@antonio tmp]$ gdb php
GNU gdb Red Hat Linux (6.0post-0.20040223.19rh)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/tls/libthread_db.so.1".
 
(gdb) run /home/lmpmbernardo/workspace/pdotest/pdodebug.php
Starting program: /usr/local/bin/php /home/lmpmbernardo/workspace/pdotest/pdodebug.php
[Thread debugging using libthread_db enabled]
[New Thread -1208597408 (LWP 1941)]
Successfully created a PDO object
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1208597408 (LWP 1941)]
_efree (ptr=0xe) at /tmp/php5-200503262330/Zend/zend_alloc.c:285
285             CALCULATE_REAL_SIZE_AND_CACHE_INDEX(p->size);
(gdb) bt
#0  _efree (ptr=0xe) at /tmp/php5-200503262330/Zend/zend_alloc.c:285
#1  0x0817ee79 in _zval_ptr_dtor (zval_ptr=0x8784dc0) at zend_variables.h:35
#2  0x0818d7a4 in zend_hash_apply_deleter (ht=0x8245c50, p=0x8784db4) at /tmp/php5-200503262330/Zend/zend_hash.c:574
#3  0x0818d816 in zend_hash_graceful_reverse_destroy (ht=0x8245c50) at /tmp/php5-200503262330/Zend/zend_hash.c:640
#4  0x0817ed4a in shutdown_executor () at /tmp/php5-200503262330/Zend/zend_execute_API.c:216
#5  0x08187da8 in zend_deactivate () at /tmp/php5-200503262330/Zend/zend.c:823
#6  0x08158832 in php_request_shutdown (dummy=0x0) at /tmp/php5-200503262330/main/main.c:1217
#7  0x081e676b in main (argc=2, argv=0xbfef8f74) at /tmp/php5-200503262330/sapi/cli/php_cli.c:1057
(gdb) quit
The program is running.  Exit anyway? (y or n) y
[lmpmbernardo@antonio tmp]$
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 06:00:01 2025 UTC | 
I see the same problem with Fedora 4 Test 3. The installation was done through rpms, except for the PDO related extensions and xdebug that I compiled myself. The lastInsertId problem exists with the pdo_mysql extension (on Fedora; on Windows works fine) but not with the pdo_sqlite extension. I think this should be fixed before 5.1 comes out... Here is another screen dump: [root@antonio tmp]# rpm -qa | grep php php-ldap-5.0.4-10 php-debuginfo-5.0.4-10 php-mysql-5.0.4-10 php-devel-5.0.4-10 php-pear-5.0.4-10 php-5.0.4-10 php-odbc-5.0.4-10 [root@antonio tmp]# php -v PHP 5.0.4 (cli) (built: May 9 2005 11:21:11) Copyright (c) 1997-2004 The PHP Group Zend Engine v2.0.4-dev, Copyright (c) 1998-2004 Zend Technologies with Xdebug v2.0.0beta2, Copyright (c) 2002, 2003, 2004, by Derick Rethans [root@antonio tmp]# php -m [PHP Modules] bz2 calendar ctype curl dbx dio exif ftp gettext gmp iconv ldap libxml mime_magic mysql mysqli odbc openssl pcntl pcre PDO pdo_mysql pdo_sqlite posix pspell session shmop SimpleXML sockets SPL standard sysvmsg sysvsem sysvshm tokenizer wddx xdebug xml yp zlib [Zend Modules] Xdebug [root@antonio tmp]# cat /home/lmpmbernardo/eclipseworks/pdotest/pdodebug.php <?php /** * $Id$ * @package pdotest */ $db = new PDO("mysql:dbname=test;host=127.0.0.1", "root", ""); //$db = new PDO("sqlite:/tmp/test.db", "", ""); echo "Successfully created a PDO object"; $db->setAttribute(PDO_ATTR_ERRMODE, PDO_ERRMODE_EXCEPTION); //$sql = "DROP TABLE pdobomb"; //$db->query($sql); try { $sql = "CREATE TABLE pdobomb(id INT(11) NOT NULL auto_increment, name VARCHAR(20), PRIMARY KEY (id))"; // $sql = "CREATE TABLE pdobomb(id INT(11) NOT NULL INTEGER, name VARCHAR(20), PRIMARY KEY (id))"; $db->exec($sql); } catch(Exception $e) { // ok; db created before... } $name = "YYYYYY"; $sql = "INSERT INTO pdobomb(id, name) VALUES(null, '$name')"; $db->exec($sql); $id = $db->lastInsertId(); echo $id; ?> [root@antonio tmp]# gdb php GNU gdb Red Hat Linux (6.3.0.0-1.24rh) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1". (gdb) run /home/lmpmbernardo/eclipseworks/pdotest/pdodebug.php Starting program: /usr/bin/php /home/lmpmbernardo/eclipseworks/pdotest/pdodebug.php Reading symbols from shared object read from target memory...done. Loaded system supplied DSO at 0x5dc000 [Thread debugging using libthread_db enabled] [New Thread -1208394880 (LWP 12293)] Successfully created a PDO object Program received signal SIGSEGV, Segmentation fault. [Switching to Thread -1208394880 (LWP 12293)] _efree (ptr=0x9) at /usr/src/debug/php-5.0.4/Zend/zend_alloc.c:263 263 CALCULATE_REAL_SIZE_AND_CACHE_INDEX(p->size); (gdb) quit The program is running. Exit anyway? (y or n) y