In Doctrine2 using some thing like:
$user = array(\'username\' => \'example\', \'passsword\' => \'changeme\');
$conn->insert(\'users\', $user);
One can use the Doctrine\DBAL\Connection::lastInsertId()
method.
It can be used with native queries as well as manually written inserts.
Example case:
$query = 'INSERT INTO blabla...';
$connection->executeUpdate($query, $params);
var_dump($connection->lastInsertId());
If using the ORM, you can obtain an instance of the connection from the entity manager:
$connection = $em->getConnection();
Note:
Aside from the technical details, I agree with @Layke for using an entity for your specific case.