|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33618 PDO LastInsertId() returns "%ld"
Submitted: 2005-07-08 18:31 UTC Modified: 2005-07-11 14:00 UTC
From: matthew_peters at uk dot ibm dot com Assigned:
Status: Closed Package: PDO related
PHP Version: 5.1.0b2 OS: WinXP
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: matthew_peters at uk dot ibm dot com
New email:
PHP Version: OS:


 [2005-07-08 18:31 UTC] matthew_peters at uk dot ibm dot com
Call to PDO LastInsertId() with the MySQL driver was working fine for me on 5.0.3 and 5.0.4 but is returning "%ld" with 5.1 b2. I am using just the php_pdo_mysql.dll extension that came with the 5.1 beta. 

Reproduce code:

$dbh = new PDO("mysql:dbname=COMPANYDB;host=localhost",'root','*******');

$stmt = 'INSERT INTO company (name) VALUES ("Acme");';
$pdo_stmt = $dbh->prepare($stmt);
$rows_affected = $pdo_stmt->execute();
$last_insert_id = $dbh->lastInsertId();
echo $last_insert_id; // gets %ld


Expected result:
What I want to see is the primary key of the row I have just inserted. The database definition by the way is:

create table company (
   id integer auto_increment,
   name char(20),
   employee_of_the_month integer,
   primary key(id) ); 

Actual result:
What I do see is %ld.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-08 18:36 UTC]
Please try using this CVS snapshot:
For Windows:

 [2005-07-08 19:02 UTC] matthew_peters at uk dot ibm dot com
Just tried this with the latest from the snapshot that iliaa  points to and got the same result. 

For the sceptical:
1. Downloaded latest (reports PHP 5.1.0-dev (cli) (built: Jul  8 2005 12:23:17)
2. enabled php.ini-dist as php.ini
3. made the extension_dir c:\php\ext
4. added the one extension php_pdo_mysql
5. ran my test program - output "%ld".
 [2005-07-08 21:27 UTC]
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
Thank you for the report, and for helping us make PHP better.

Will be fixed in the next snapshot.
 [2005-07-11 14:00 UTC] matthew_peters at uk dot ibm dot com
I concur - fixed in the latest build. Many thanks.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Oct 17 19:03:35 2021 UTC