Get last inserted ID from doctrine and native mysql query

Viewed 17928

I'm using doctrine in symfony2. But I used native mysql query to insert some data. Now I want the last inserted id from the database. My code looks like:

$stmt = $this->getDoctrine()->getManager()
             ->getConnection()
             ->prepare("INSERT INTO tb_company (v1,v2,v3) values('$v1','$v2','$v3')");
$stmt->execute();

So to recover the last inserted id I tried

$stmt->insert_id; 

$id=LAST_INSERT_ID(id)

$id=$stmt->getId();

and many other. None of them worked for me. I'm new to doctrine. How to get the last inserted ID from here? What I'm missing?

1 Answers
Related