Witam,

W PHP manual pisze:

"While PDO has its advantages, such as a clean, simple, portable API, its main disadvantage is that it doesn't allow you to use all of the advanced features that are available in the latest versions of MySQL server. For example, PDO does not allow you to use MySQL's support for Multiple Statements"

Tak więc gdy robię:

  1. $conn->query("CALL nazwaProcedury();");
  2. $conn->query("SELECT cos FROM tabela");

wyświetla się błąd

ponieważ zgodnie z MySQL manualem
"Multiple-result processing also is required if you execute CALL statements for stored procedures (...)".
zwraca 2 rezultaty, "główny" oraz status błędu

Da się to jakoś obejść ?

Wymyśliłem taki kod:
  1. $q = $conn->query("SELECT 1 as one; SELECT 2 as two; SELECT 3 as three;");
  2.  
  3. do
  4. {
  5. $r=$q->fetchAll(PDO::FETCH_ASSOC);
  6. echo "<br />";
  7. print_r($r);
  8.  
  9. }while($q->nextRowset());
  10.  
  11. //ZMIENIAM NAZWE $q na $a
  12. $a = $conn->query("SELECT 1 as one; SELECT 2 as two; SELECT 3 as three;");
  13.  
  14. do
  15. {
  16. $r=$a->fetchAll(PDO::FETCH_ASSOC);
  17. echo "<br />";
  18. print_r($r);
  19.  
  20. }while($a->nextRowset());


tylko nie rozumiem dlaczego muszę tworzyć nową nazwę instancji klasy.

W taki sposób:
  1. $q = $conn->query("SELECT 1 as one; SELECT 2 as two; SELECT 3 as three;");
  2.  
  3. do
  4. {
  5. $r=$q->fetchAll(PDO::FETCH_ASSOC);
  6. echo "<br />";
  7. print_r($r);
  8.  
  9. }while($q->nextRowset());
  10.  
  11. //tu zostawiam $q
  12. $q = $conn->query("SELECT 1 as one; SELECT 2 as two; SELECT 3 as three;");
  13.  
  14. do
  15. {
  16. $r=$q->fetchAll(PDO::FETCH_ASSOC);
  17. echo "<br />";
  18. print_r($r);
  19.  
  20. }while($q->nextRowset());

robiąc tak z drugiego multi statement wykona się tylko SELECT 1 as one;

Pytanie drugie odnośnie tego. Wie ktoś jak pobrać ze stored procedures:
"The final result from the procedure is a status result that includes no result set. The status indicates whether the procedure succeeded or an error occurred."
ten status?

Pozdrawiam