Augus
Augus

Reputation: 495

How to get back the last inserted row mysql

Alright I have been looking for this for a while now, and didn't really found an answer to my problem.

At the moment I got this syntax:

$sql = sprintf("INSERT INTO users (***, ***, ***, ***) VALUES ('%s', '%s', '%s', %d)", mysql_real_escape_string($***), mysql_real_escape_string($***), mysql_real_escape_string($***), $***);
if(!mysql_query($sql)) { die('error: '.mysql_error()); }
return mysql_insert_id();

And this works fine, and when I want to get an item back from the last inserted row I could do another query with the id I get back.

But my question is, is it possible to give back the whole row at once? So that I don't have to run another query to get an item from the last inserted row.

Upvotes: 0

Views: 1051

Answers (1)

Luca Rainone
Luca Rainone

Reputation: 16458

No, nothing like that is implemented.

I think it's right, because the insert syntax is more complex (see for example on duplicate key, insert ignore), and in some case the expected return could be ambiguous

Upvotes: 1

Related Questions