NimmoNet NimmoNet - 1 year ago 189
PHP Question

Doctrine2 Insert and retrieve new insert ID

In Doctrine2 using some thing like:

$user = array('username' => 'example', 'passsword' => 'changeme');

$conn->insert('users', $user);

How would I then get the last ID of the user I just inserted? If it is not possible to do this then how do you gen a id so that you can the following:

$id = //something here.
$user = array('username' => 'example', 'passsword' => 'changeme', 'id' => $id);
$conn->insert('users', $user);

Answer Source

If you are using the ORM


if you are using the DBAL:


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download