Jump to content

Archived

This topic is now archived and is closed to further replies.

Prismatic

Multiple update / insert's in one query?

Recommended Posts

So on my forums I notice I am using a lot of queries to get what I need done, which is not so good in practice. Is there a wat to update or insert different data into multiple tables using one query? (Updates and inserts in different queries) ? Not sure if it's even possible :(

Share this post


Link to post
Share on other sites
Not really, but PHP's mysqli extension has a mysqli_multi_query() function that sends several queries at once. mysqli is still not supported by a lot of web hosts though.

Share this post


Link to post
Share on other sites
The best thing you can do here ( involves a bit more work) is to re-think your code, see if you can't get all the insert/update data in one place so you only have to run 1, possibly 2 queries per table.

This depends on what your doing but if it's a placement issue that causes you to run 2 queries on the same table you can throw some data into a temporary $_SESSION, then extract it from the array when your ready to run the query, that can help cut down on the amount of queries.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.