fastsol Posted June 20, 2015 Share Posted June 20, 2015 I am using PDO and have the PDO::ATTR_EMULATE_PREPARES => false set. So it doesn't seem to allow for multiple query strings in a single query call. Is there a way around this or a different method that is used in such circumstances? I don't believe transactions is what I'm looking for cause the queries wouldn't be dependent on each other in a certain order. Just more for multiple INSERT or UPDATE kind of things. Quote Link to comment https://forums.phpfreaks.com/topic/296935-how-do-i-run-multiple-queries-in-one-query-call/ Share on other sites More sharing options...
Solution Barand Posted June 21, 2015 Solution Share Posted June 21, 2015 (edited) Just more for multiple INSERT or UPDATE kind of things. Multiple insert INSERT INTO tablename (col1, col2) VALUES (1, 'AAA'),(2,'BBB'),(3,'CCC'); Multiple update UPDATE tablename SET col2 = CASE id WHEN 1 THEN 'DDD' WHEN 2 THEN 'EEE' WHEN 3 THEN 'FFF' ELSE col2 END Edited June 21, 2015 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/296935-how-do-i-run-multiple-queries-in-one-query-call/#findComment-1514497 Share on other sites More sharing options...
jazzman1 Posted June 21, 2015 Share Posted June 21, 2015 Barry, I think he is looking for stored procedures or trigers. fastsol, stored procedures provide SQL enhancements supporting variables, comments, exceptions, conditional testing and looping as programming elements. Quote Link to comment https://forums.phpfreaks.com/topic/296935-how-do-i-run-multiple-queries-in-one-query-call/#findComment-1514509 Share on other sites More sharing options...
fastsol Posted June 21, 2015 Author Share Posted June 21, 2015 Although Barand had the answer I was looking for, I did research the stored procedures method and have added it to my knowledge. Quote Link to comment https://forums.phpfreaks.com/topic/296935-how-do-i-run-multiple-queries-in-one-query-call/#findComment-1514514 Share on other sites More sharing options...
mac_gyver Posted June 21, 2015 Share Posted June 21, 2015 and the multi-value update can be implemented as the following without having to dynamically produce case logic in the query (assuming that id is a unique index) - INSERT INTO tablename (id,col2) VALUES (1,'AAA'),(2,'BBB'),(3,'CCC') ON DUPLICATE KEY UPDATE col2=VALUES(col2) 1 Quote Link to comment https://forums.phpfreaks.com/topic/296935-how-do-i-run-multiple-queries-in-one-query-call/#findComment-1514521 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.