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:
<?php
include '../inc/db.inc.php';
if (isset($_POST['number']) OR
isset($_POST['name'])) {
try
{
$sql = "CREATE TABLE IF NOT EXISTS `table1` (
`id_receipts` INT(10) NOT NULL AUTO_INCREMENT,
`number` VARCHAR(255),
`name` VARCHAR(255),
`date` DATETIME,
PRIMARY KEY (id_receipts)
)ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;
INSERT INTO `glizing` SET
number = :number,
name = :name,
date = :date";
$s = $pdo->prepare($sql);
$s->bindValue(':number', $_POST['number']);
$s->bindValue(':name', $_POST['name']);
$s->bindValue(':date', $_POST['date']);
$s->execute();
}
catch (PDOException $e)
{
$error = 'Błąd przy zapisie: ' . $e->getMessage();
include '../inc/error.inc.php';
}
}
if (isset($_POST['autor']) OR
isset($_POST['additinfo'])) {
try
{
include_once 'getid.php'; //pobiera wartość $idreceipt
$sql1 = "CREATE TABLE IF NOT EXISTS `table2` (
`id_receipts` INT(10),
`additinfo` TEXT,
`autor` VARCHAR(255),
PRIMARY KEY (id_greceipts)
)ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;
INSERT INTO `glizinginfo` SET
autor = :autor,
additinfo = :additinfo,
id_receipts = :id_receipts";
$s1 = $pdo->prepare($sql1);
$s1->bindValue(':autor', $_POST['autor']);
$s1->bindValue(':additinfo', $_POST['additinfo']);
$s1->bindValue(':id_receipts', $idreceipt);
$s1->execute();
}
catch (PDOException $e)
{
$error = 'Błąd przy zapisie: ' . $e->getMessage();
include '../inc/error.inc.php';
}
}
if (isset($_POST['deliverydate']) OR
isset($_POST['storage'])) {
try
{
include_once 'getid.php'; //pobiera wartość $idreceipt
for($i=0
, $count = count($_POST['deliverydate']) ;$i < $count; $i++) { if (empty(trim($_POST['deliverydate'][$i])) && empty(trim($_POST['storage'][$i]))) continue
; $values[] = '("' .$idreceipt. '","' . $_POST['deliverydate'][$i] . '","' . $_POST['storage'][$i] . '")';
}
$sql2 = "CREATE TABLE IF NOT EXISTS `table3` (
id_receipts INT(10) NOT NULL,
deliverydate DATE,
storage TEXT
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;
INSERT INTO table3 (id_receipts, deliverydate, storage) VALUES " . implode(',', $values); $s2 = $pdo->prepare($sql2);
$s2->execute();
}
catch (PDOException $e)
{
$error = 'Błąd przy dodawaniu wpisu: ' . $e->getMessage();
include '../inc/error.inc.php';
}
}
?>
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?