Doctrine2 and raw sql: get last inserted ID

doctrine-orm, php, symfony

Solution

You'll want to use lastInsertId().

Example:

$dbh = Doctrine_Manager::getInstance()->getCurrentConnection();
$sth = $dbh->prepare("INSERT INTO continent (created_at, updated_at) VALUES ( NOW(), NOW() )");
$sth->execute();

$conn = Doctrine_Manager::getInstance()->getCurrentConnection();
$conn->lastInsertId('continent_id');

Problem

I have something like this: ``` $stmt = $this->getDoctrine()->getConnection()->prepare( 'insert into someTable (columnList) values (parameters);'); /* bind parameters */ $stmt->execute(); ``` How do I get the last inserted ID? Thanks, Scott

Original source