Doctrine2 Insert and retrieve new insert ID

后端 未结 4 1706
轮回少年
轮回少年 2020-12-30 18:30

In Doctrine2 using some thing like:

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

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


        
4条回答
  •  [愿得一人]
    2020-12-30 19:22

    If you are using the ORM

    $em->persist($object);
    $em->flush();
    $object->getId();
    

    if you are using the DBAL:

    $conn->lastInsertId();
    

    http://www.doctrine-project.org/api/dbal/2.5/class-Doctrine.DBAL.Connection.html#_lastInsertId

提交回复
热议问题