CodeIgniter Forums
how to set PDO::MYSQL_ATTR_USE_BUFFERED_QUERY - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17)
+--- Thread: how to set PDO::MYSQL_ATTR_USE_BUFFERED_QUERY (/showthread.php?tid=67232)



how to set PDO::MYSQL_ATTR_USE_BUFFERED_QUERY - prashant.nirgun - 01-30-2017

I desperately required help please help me its urgent. I am using Codeigniter 3.1 Version and trying to use MySQL 5.5. When I am calling Stored Procedure back to back 2 times its giving the error. Anybody know how to fix this ? **** code ****************

public function foo()
{
//test_sp,test1_sp;
echo "called sp1 <br>";
$sql = "CALL test_sp()";
$query = $this->db->query($sql);
var_dump( $query->result());

echo "<br> called sp2 <br>";
$sql2 = "CALL test1_sp()";
$query2 = $this->db->query($sql2);
var_dump($query2->result());
}
********** out put ***********

Error Number: HY000/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.

CALL test1_sp() Filename: controllers/Test.php Line Number: 27


RE: how to set PDO::MYSQL_ATTR_USE_BUFFERED_QUERY - prashant.nirgun - 01-30-2017

I even tried out unbuffered row() but it still fails.
while ($row = $query->unbuffered_row())
{ var_dump($row);
}

I tried setting pdo attribues like system/database/drivers/pdo/pdo_driver.php

public function db_connect($persistent = FALSE)
try {
$this->options[PDO::MYSQL_ATTR_USE_BUFFERED_QUERY] = FALSE;
return new PDO($this->dsn, $this->username, $this->password, $this->options);
}

No success all my data is coming from mysql stored procedure its not even containing the large result set.


[SOLVED] how to set PDO::MYSQL_ATTR_USE_BUFFERED_QUERY - prashant.nirgun - 02-03-2017

I need to call two stored procedure one after another and it was giving me the error.
I solved this by using the following code.

$sql = "CALL test_sp()";
$stmt = $this->db->conn_id->prepare($sql);
$result = $stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
var_dump($result);

We can use any Select statement instead of Stored Procedure only thing is to use in try catch