Getting last ID inserted into DB - value returned is "array" string?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dbrewerton
    New Member
    • Nov 2009
    • 115

    #1

    Getting last ID inserted into DB - value returned is "array" string?

    Hello folks, I'm trying to figure out how to get the last inserted ID from my database. The query runs but instead of getting the actual number inserted, I get the word Array returned. Here's the code, let me know how to fix this. Thanks! For what its worth, this is MySQL running PHP and the DB connection I believe is PDO.

    Code:
    	$query = $db->prepare("SELECT id from orders ORDER BY id DESC LIMIT 1");
    	$query->execute();
    	$order_number = $query->fetch();
    	$order_number++;
  • dbrewerton
    New Member
    • Nov 2009
    • 115

    #2
    I finally figured it out. I had to query that Last Inserted ID outside the MySQL Execute statement.

    Comment

    Working...