2

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?

1
  • 1
    What kind of data, that you are inserting, you don't know so you have to retrieve it? Apart from the id, of course. Commented May 21, 2012 at 23:44

1 Answer 1

5

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();

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.