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
Post a Comment