0

I would like to generate a multiple queries with PDO, but $result give me only the first request, after many tests, I ask your help.

  $sql = 'SELECT * FROM `tablel`
  WHERE `c_id`= 1;SELECT * FROM `table2`';
  $query = $db->prepare($sql);
  $query->execute();
  $result = $query->fetchAll(PDO::FETCH_ASSOC);
lapomme27
  • 13
  • 2
  • 3
    You can only do one query at a time. But is that bad? Just do one first, and then the other. – KIKO Software Jun 13 '22 at 20:43
  • isn't it safe to perform a multi-query rather than several single queries? – lapomme27 Jun 13 '22 at 20:46
  • See the last answer at the linked question for how to fetch the results from multiple queries. – Barmar Jun 13 '22 at 20:47
  • 1
    Safety doesn't come into it. Queries are always execute one after the other. – KIKO Software Jun 13 '22 at 20:48
  • You are only making more work for yourself if you want to send the queries in bulk to the server. Just execute them one by one; you lose nothing. – Dharman Jun 13 '22 at 20:49
  • 1
    You can use a transaction if you need to be certain that all of the queries are executed together. – Don't Panic Jun 13 '22 at 20:50
  • OK, if by "safe" you mean you are worried that your database is not consistent anymore, when only half of the queries you planned to execute, are actually executed, then the advice of Don't Panic is valid. I also see this question is closed and shows an answer that does allow you to execute multiple queries. Please note that this is not the same as a transaction, using emulated prepared statements to execute multiple queries is, in the background, simply going through the list of queries one by one. – KIKO Software Jun 13 '22 at 20:56
  • Thanks for the transcation idea but I don't need it. I just thought it was better to run a multiple query rather than multiple single queries, from a security point of view. – lapomme27 Jun 13 '22 at 21:29

0 Answers0