Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Błąd przy dodawaniu wpisu: SQLSTATE[HY000], Wykonanie zapytani przed końcem wykonania poprzedniego.
lustfingers
post 9.04.2017, 17:12:26
Post #1





Grupa: Zarejestrowani
Postów: 99
Pomógł: 5
Dołączył: 18.03.2015

Ostrzeżenie: (0%)
-----


Witam,

Podczas wykonywania zapisu do bazy otrzymuje komunikat:

Błąd przy dodawaniu wpisu: SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.

Z tego co rozumie to zapytanie numer 2 się jeszcze nie skończyło a numer 3 chce się zacząć i to powoduje błąd.

Tak wygląda kod:

  1. <?php
  2. ini_set( 'display_errors', 'On' );
  3. error_reporting( E_ALL );
  4. include '../inc/db.inc.php';
  5.  
  6. if (isset($_POST['number']) OR isset($_POST['name']))
  7. {
  8. try
  9. {
  10. $sql = "CREATE TABLE IF NOT EXISTS `table1` (
  11. `id_receipts` INT(10) NOT NULL AUTO_INCREMENT,
  12. `number` VARCHAR(255),
  13. `name` VARCHAR(255),
  14. `date` DATETIME,
  15. PRIMARY KEY (id_receipts)
  16. )ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;
  17. INSERT INTO `glizing` SET
  18. number = :number,
  19. name = :name,
  20. date = :date";
  21. $s = $pdo->prepare($sql);
  22. $s->bindValue(':number', $_POST['number']);
  23. $s->bindValue(':name', $_POST['name']);
  24. $s->bindValue(':date', $_POST['date']);
  25. $s->execute();
  26. }
  27. catch (PDOException $e)
  28. {
  29. $error = 'Błąd przy zapisie: ' . $e->getMessage();
  30. include '../inc/error.inc.php';
  31. exit();
  32. }
  33. }
  34.  
  35.  
  36. if (isset($_POST['autor']) OR isset($_POST['additinfo']))
  37. {
  38. try
  39. {
  40. include_once 'getid.php'; //pobiera wartość $idreceipt
  41. $sql1 = "CREATE TABLE IF NOT EXISTS `table2` (
  42. `id_receipts` INT(10),
  43. `additinfo` TEXT,
  44. `autor` VARCHAR(255),
  45. PRIMARY KEY (id_greceipts)
  46. )ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;
  47. INSERT INTO `glizinginfo` SET
  48. autor = :autor,
  49. additinfo = :additinfo,
  50. id_receipts = :id_receipts";
  51. $s1 = $pdo->prepare($sql1);
  52. $s1->bindValue(':autor', $_POST['autor']);
  53. $s1->bindValue(':additinfo', $_POST['additinfo']);
  54. $s1->bindValue(':id_receipts', $idreceipt);
  55. $s1->execute();
  56. }
  57. catch (PDOException $e)
  58. {
  59. $error = 'Błąd przy zapisie: ' . $e->getMessage();
  60. include '../inc/error.inc.php';
  61. exit();
  62. }
  63. }
  64.  
  65.  
  66. if (isset($_POST['deliverydate']) OR isset($_POST['storage']))
  67. {
  68. try
  69. {
  70. include_once 'getid.php'; //pobiera wartość $idreceipt
  71. $values = array();
  72. for($i=0, $count = count($_POST['deliverydate']) ;$i < $count; $i++) {
  73. if (empty(trim($_POST['deliverydate'][$i])) && empty(trim($_POST['storage'][$i]))) continue;
  74. $values[] = '("' .$idreceipt. '","' . $_POST['deliverydate'][$i] . '","' . $_POST['storage'][$i] . '")';
  75. }
  76. $sql2 = "CREATE TABLE IF NOT EXISTS `table3` (
  77. id_receipts INT(10) NOT NULL,
  78. deliverydate DATE,
  79. storage TEXT
  80. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;
  81. INSERT INTO table3 (id_receipts, deliverydate, storage) VALUES " . implode(',', $values);
  82. $s2 = $pdo->prepare($sql2);
  83. $s2->execute();
  84. }
  85. catch (PDOException $e)
  86. {
  87. $error = 'Błąd przy dodawaniu wpisu: ' . $e->getMessage();
  88. include '../inc/error.inc.php';
  89. exit();
  90. }
  91.  
  92. header('Location: .');
  93. exit();
  94. }
  95.  
  96. ?>


Gdy nie było zapytania do table2 to wszystko działało teraz wartości z table3 nie są zapisywane w bazie tylko wyświetla sie ten błąd, stąd moje pytanie jak najprościej obsłużyć te zapytania?
Go to the top of the page
+Quote Post
Pyton_000
post 9.04.2017, 18:51:28
Post #2





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


A po co za każdym razem odpalać te create table. Nie możesz tego ręcznie 1 raz odpalić i mieć z głowy?
Go to the top of the page
+Quote Post
lustfingers
post 9.04.2017, 20:02:27
Post #3





Grupa: Zarejestrowani
Postów: 99
Pomógł: 5
Dołączył: 18.03.2015

Ostrzeżenie: (0%)
-----


Dzięki.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 12:47