John
John

Reputation: 6268

Get the results from a mysql_query insert

After I insert values into a new row, I need the results from that query. mysql_query() only returns true or false when doing a INSERT command. The only solution I can think of for something like this is by creating a temporary number/id in PHP and inserting it into its own column. Then fetching that row it with a second command. However it may be possible that my random id is not random enough to accidentally select the wrong row when the script is executed multiple times.

Is there a way to execute the INSERT command on a mysql_query() call so that it returns the rows created?

Upvotes: 2

Views: 1113

Answers (1)

John Conde
John Conde

Reputation: 219804

It sounds like you should be using AUTO_INCREMENT and mysql_insert_id(). AUTO_INCREMENT will create a unique ID for each row automatically which you can retrieve using mysql_insert_id();

Upvotes: 5

Related Questions