php - PDO - best way to get row after insert into database -


After inserting, I already know a method to get the line. Something like this:

  // database $ id = $ PDO-> lastInsertId (); $ Lastrow = $ PDO- & gt; Query ("SELECT * FROM table WHERE id = $ id") - & gt; fetchObject ();   

However, I am afraid that this is not the best solution, is there any better way in this matter?

This is not apparently the best because it does not prepare statements

 < Code> $ id = $ PDO- & gt; Last InsertID (); $ Stmt = $ PDO- & gt; Ready ("SELECT * FROM table WHERE id =?"); $ Stmt- & gt; Execute ([$ id]); $ lastrow = $ stmt-> Fetch object ();         



Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -