Today I changed mysql to PDO. And now I have this little problem.
So when I used mysql, and wanted to know the id of the row I just inserted I just had to do this:
$id = $obj_db_write->insert("reservations",$arr_kolommen,$arr_waardes);
When I printed the $id I got: (for example:) 5462
When I use the same line now, I get 1 as Id.
Problem:
When the line is inserted, other columns are using that ID for adding fields in other tables.
So now I get this error:
Warning:
PDO::query() [pdo.query]: SQLSTATE[23000]:
Integrity constraint violation: 1062 Duplicate entry'1-double'for key'RSVR_ID'
in/data/local/www/wereldreizen/html/phpclasses/class_db.phpon line 229
What’s quite expected because the RSVR_ID is 1, and 1 is already inserted.
Does someone know where I’m wrong?
Thanks in advance!
With PDO, you don’t get the newly inserted ID as result from a query. Use
instead. In your case, that could e.g. look like that:
Check out http://www.php.net/manual/de/book.pdo.php for the full PDO API.