Hello. I have such a problem. I need to add a record to the database and at the same time find out immediately what ID value will be given to it by the auto-increment in the database.

 if (isset($data['send_album'])) { $tr = R::dispense('lyrics'); $tr->name = "newName"; R::store($tr); } 

I use RedBeanPHP to work, so I can’t figure out how to implement it using the tools.

    3 answers 3

    I answer my own question. In order to display the RedBean ID last element in the database, you simply need to refer to this entity and its ID after the R::store() method

      $newAlbum = R::dispense('albums'); $newAlbum->album_name = "new"; R::store($newAlbum); echo $newAlbum->id; 

      Everything is just $ tr is your entry, ask her id after R :: store ($ tr); Something like $ tr ["id"];

       if (isset($data['send_album'])) { $tr = R::dispense('lyrics'); $tr->name = "newName"; R::store($tr); echo $tr["id"]; //Решение проблемы } 
         $id = R::store($tr); 

        Did not deal with RedBeanPHP, but ORM usually returns something worth checking out.

        • This method does not work. - PetrCool