Kamis, 12 Maret 2009

Memanggil multi store procedure di PDO Symfony

Mungkin ada yang pernah mengalami ini saat exec store procedure:

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.

error itu muncul karena terjadi karena pemanggilan store procedure dalam sekali runtime lebih dari satu procedure.

contoh nya seperti ini (ini hanya potongan script aja)
$this->con = $this->getContext()->getInstance()->getDatabaseConnection('pdo');

$stmt = $this->con->prepare("call sp_const_simpan(0, null, :nama, '048')");
$stmt->bindParam(':nama', $nama);
$stmt->execute();

$stmt = $this->con->prepare("call sp_const(:kode)");
$stmt->bindParam(':kode', $kode, PDO::PARAM_STR, 8);
$stmt->execute();

pasti itu hasilnya error, cara mengatasinya itu tambahkan $stmt->closeCursor();
$this->con = $this->getContext()->getInstance()->getDatabaseConnection('pdo');

$stmt = $this->con->prepare("call sp_const_simpan(0, null, :nama, '048')");
$stmt->bindParam(':nama', $nama);
$stmt->execute();
$stmt->closeCursor();

$stmt = $this->con->prepare("call sp_const(:kode)");
$stmt->bindParam(':kode', $kode, PDO::PARAM_STR, 8);
$stmt->execute();

Tidak ada komentar:

Posting Komentar