Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.5.0b5

Bug #9966 Returns an error when using $mdb2->lastInsertId() and not an id.
Submitted: 2007-01-29 19:53 UTC
From: macsnoeren at gmail dot com Assigned: quipo
Status: Closed Package: MDB2 (version 2.3.0)
PHP Version: 4.3.11 OS: Linux
Roadmaps: (Not assigned)    
Subscription  


 [2007-01-29 19:53 UTC] macsnoeren at gmail dot com (Maurice Snoeren)
Description: ------------ After a insert query I want to get the ID of the the record which is just added to the database. The table definition is very simple and got an 'id' collumn which is the primary key of the table. When performing the insert query with $mbd2->query($q) I use the function $mbd2->lastInsertID() to get the ID. However I only get an PEAR::Error which contains the debug error: unable to find package 'MDB2_Datatype' file 'MDB2/Datatype.php' After searhing on the internet and on the MDB2 pear site I saw that the MDB2_Datatype.php does not exists in the package. I could not find it eventually. After a lot of searching I could not determine the problem and that is the reason I post it to the bug report. Test script: --------------- <?php require_once 'MDB2.php'; $dsn = 'mysql://user:password@localhost/database'; // Used table definition // // CREATE TABLE MDB2_TEST // ( id INT(11) PRIMARY KEY AUTO_INCREMENT, // naam varchar(60), // password varchar(60), // date timestamp // ); $mdb2 =& MDB2::connect($dsn); // Also tried factory! if (PEAR::isError($mdb2)) { die($mdb2->getMessage() . "\n"); } $query = "INSERT INTO MDB2_TEST ( naam, password ) VALUES ( 'test', 'test' )"; $res =& $mdb2->query($query); if (PEAR::isError($res)) { die($res->getMessage() . "\n"); } $id =& $mdb2->lastInsertID(); if (PEAR::isError($id)) { print_r($id); print "ID error\n"; die($id->getMessage() . "\n"); } print "ID: '$id'\n"; ?> ------------------ Result: Dump of the PEAR::Error which shows that: unable to find package 'MDB2_Datatype' file 'MDB2/Datatype.php' ID error MDB2 Error: not found Expected result: ---------------- ID: '2' When the inserted record got ID 2. Actual result: -------------- ~maurice>./testmdb2.php mdb2_error Object ( [error_message_prefix] => [mode] => 1 [level] => 1024 [code] => -4 [message] => MDB2 Error: not found [userinfo] => unable to find package 'MDB2_Datatype' file 'MDB2/Datatype.php' [backtrace] => Array ( [0] => Array ( [file] => /mnt/d2/opt/pear/lib/php/MDB2.php [line] => 962 [function] => pear_error [class] => mdb2_error [type] => -> [args] => Array ( [0] => MDB2 Error: not found [1] => -4 [2] => 1 [3] => 1024 [4] => unable to find package 'MDB2_Datatype' file 'MDB2/Datatype.php' ) ) [1] => Array ( [file] => /mnt/d2/opt/pear/lib/php/PEAR.php [line] => 564 [function] => mdb2_error [class] => mdb2_error [type] => -> [args] => Array ( [0] => -4 [1] => 1 [2] => 1024 [3] => unable to find package 'MDB2_Datatype' file 'MDB2/Datatype.php' ) ) [2] => Array ( [file] => /mnt/d2/opt/pear/lib/php/MDB2.php [line] => 575 [function] => raiseerror [class] => pear [type] => :: [args] => Array ( [0] => [1] => -4 [2] => [3] => [4] => unable to find package 'MDB2_Datatype' file 'MDB2/Datatype.php' [5] => MDB2_Error [6] => 1 ) ) [3] => Array ( [file] => /mnt/d2/opt/pear/lib/php/MDB2.php [line] => 341 [function] => raiseerror [class] => mdb2 [type] => :: [args] => Array ( [0] => -4 [1] => [2] => [3] => unable to find package 'MDB2_Datatype' file 'MDB2/Datatype.php' ) ) [4] => Array ( [file] => /mnt/d2/opt/pear/lib/php/MDB2.php [line] => 1847 [function] => loadclass [class] => mdb2 [type] => :: [args] => Array ( [0] => MDB2_Datatype [1] => 0 ) ) [5] => Array ( [file] => /mnt/d2/opt/pear/lib/php/MDB2.php [line] => 3393 [function] => loadmodule [class] => mdb2_driver_mysql [type] => -> [args] => Array ( [0] => Datatype [1] => [2] => 1 ) ) [6] => Array ( [file] => /mnt/d2/opt/pear/lib/php/MDB2.php [line] => 2565 [function] => setresulttypes [class] => mdb2_bufferedresult_mysql [type] => -> [args] => Array ( [0] => integer ) ) [7] => Array ( [file] => /mnt/d2/opt/pear/lib/php/MDB2.php [line] => 2505 [function] => _wrapresult [class] => mdb2_driver_mysql [type] => -> [args] => Array ( [0] => Resource id #8 [1] => integer [2] => 1 [3] => [4] => 0 [5] => 0 ) ) [8] => Array ( [file] => /mnt/d2/opt/pear/lib/php/MDB2.php [line] => 3190 [function] => query [class] => mdb2_driver_mysql [type] => -> [args] => Array ( [0] => SELECT LAST_INSERT_ID() [1] => integer ) ) [9] => Array ( [file] => /mnt/d2/opt/pear/lib/php/MDB2/Driver/mysql.php [line] => 1034 [function] => queryone [class] => mdb2_driver_mysql [type] => -> [args] => Array ( [0] => SELECT LAST_INSERT_ID() [1] => integer ) ) [10] => Array ( [file] => /mnt/d1/server/www/rudolf/site/dev/components/orm/bin/testmdb2.php [line] => 23 [function] => lastinsertid [class] => mdb2_driver_mysql [type] => -> [args] => Array ( ) ) ) [callback] => ) ID error MDB2 Error: not found

Comments

 [2007-01-29 21:00 UTC] quipo (Lorenzo Alberton)
I cannot reproduce the error. Are you using MDB2 2.3.0 and MDB2_Driver_mysql 1.3.0?
 [2007-01-29 22:14 UTC] macsnoeren at gmail dot com
Yep, i'm using the latest stable releases. MDB2 2.3.0 and MDB2_Driver_mysql 1.3.0. Mmmm. You are getting the correct result?
 [2007-01-30 19:56 UTC] macsnoeren at gmail dot com
Is there any dependecies I need to install for a working MDB2 version?
 [2007-01-30 20:14 UTC] quipo (Lorenzo Alberton)
No other dependency, no. From your error message it looks like the mysql driver isn't correctly loaded, it should load the file MDB2/Driver/Datatype/mysql.php instead of the non-existing MDB2/Datatype.php. Anyway, I really can't reproduce your error. It works just fine here. If you can dig further, and find something fishy or plain incorrect, please let me know, because I can't find anything wrong :-|
 [2007-01-31 13:21 UTC] macsnoeren at gmail dot com
After you're comment I searched what could went wrong. And indeed the mysql driver was not correctly setup. I do not know why, but now it works. Thanks for you're input.
 [2007-01-31 13:36 UTC] quipo (Lorenzo Alberton)
I'm glad you solved your issue.
 [2007-02-05 11:15 UTC] dkthompson at gmail dot com (Darren)
Iam getting the exact same error how was this resolved?
 [2007-02-07 15:30 UTC] tj42 at free dot fr (Richard)
Try to insert this line in the first or your file : ini_set("include_path", realpath(dirname(__FILE__).'/pear').'/'); it was ok for me (sorry for my english but i'm french! mdr)
 [2007-02-07 15:34 UTC] davidc (David Coallier)
Perhaps you could try uninstalling MDB2 and MDB2_Driver_mysql and re-install them. Or at least the MDB2 driver. After this, if it still didn't work, look at your credentials (user/pass/db/host). Should be fine.