PDO with multiple queries

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
tsdesai7
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Mar 09, 2017 12:46 am

Thu Mar 09, 2017 3:23 am

Hello
I wanted suggestion how best to use PDO for the below queries. I have multiple queries to run.
1)insert in table A
2) delete from table B if the entry exists with the ID_A
3) re-insert new entries in table B
4) delete from table C if the entry exists with the ID_A
5) re-insert new entries in table C

What would be the best /optimal way to do this in terms of MYSQL/PHP server resources.

Many Thanks,
T
chorn
php-forum GURU
php-forum GURU
Posts: 654
Joined: Fri Apr 01, 2016 2:18 am

Thu Mar 09, 2017 3:53 am

prepare your queries and execute them with bind values as you need.
NigelRen
php-forum GURU
php-forum GURU
Posts: 622
Joined: Fri Aug 05, 2011 9:53 am

Thu Mar 09, 2017 4:46 am

If you use DELETE using a WHERE EXISTS clause, this can make the deleting as simple as possible.
It's also worth (if possible) using INSERT.... SELECT type statements to create your data, this allows you to reduce the number of statements and database roundtrips that you have to do.

[Edit: this is more for bulk updates than individual rows - should read the question a bit more next time :-/]
tsdesai7
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Mar 09, 2017 12:46 am

Thu Mar 09, 2017 6:05 am

chorn wrote:
Thu Mar 09, 2017 3:53 am
prepare your queries and execute them with bind values as you need.
Thank you , I will try and let you know how i get on.
Post Reply