Welcome Guest, Not a member yet? Register   Sign In
MySQL: Inserting data based on insert_id, in a single query?
#4

[eluser]mattpointblank[/eluser]
Unless this code is going to run on every pageload, it's not really an issue running it as two queries. It's better to have code that requires multiple database hits to be used for adding/updating content, rather than viewing it or something instead. Unless your site is getting tons of use this should be fine.

One alternative could be a stored procedure, but that will still end up doing two queries either way.

EDIT: You can insert several rows at once with an INSERT query. Maybe if you're doing lots of bulk inserts, loop through all your first INSERT queries, store the resulting ID in an array (along with the data for the second query) and run all of those queries at the end.


Messages In This Thread
MySQL: Inserting data based on insert_id, in a single query? - by El Forum - 05-05-2010, 04:15 AM



Theme © iAndrew 2016 - Forum software by © MyBB