0

I'm getting an error message: Call to undefined method PDO::last_Insert_Id()

Here's my code:

$testcode = $conn -> prepare("INSERT INTO tblCategory
                             (Category, DisplayOrder)
                             VALUES('Test', 0)");
try {
            $testcode ->execute();
            $ID = $conn->last_Insert_Id();
}

catch (PDOException $e) 
    {echo $e->getMessage(); 
}

var_dump($conn instance of PDO) returns bool(true) so $conn is the PDO connection.

How do I correct so I don't get the error? I do need that last inserted id. Thanks.

DBerg
  • 159
  • 1
  • 1
  • 7

1 Answers1

0

This PDO method is called lastInsertId(), not last_Insert_Id().

So:

$ID = $conn->lastInsertId();
GMB
  • 216,147
  • 25
  • 84
  • 135