Framework: [Bug] DB::statement "cannot execute queries while other unbuffered queries exist"

Created on 27 Jun 2013  路  4Comments  路  Source: laravel/framework

I have a stored procedure in my database that I want to remove on rollback. Since laravel does not have direct support for stored procedures, I do this:

public function down()
{
    DB::statement('DROP PROCEDURE IF EXISTS MyProcedure');
}

The statement fails to delete and I get the following error:

[Exception]                                                                                                                                                                                                                                 
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. (SQL: DROP PROCEDURE IF EXISTS MyProcedure) (Bindings: array())

Then I try it like this:

public function down()
{
    DB::connection()->getPdo()->exec('DROP PROCEDURE IF EXISTS MyProcedure');
}

And it works perfectly.

Most helpful comment

DB::raw('DROP PROCEDURE IF EXISTS MyProcedure');

All 4 comments

Okay, I understand now. My confusion comes from the API docs not mentioning DB::Statement('...') it was a prepared query. It simply says

Execute an SQL statement and return the boolean result.

http://laravel.com/api/class-Illuminate.Database.Connection.html#_statement

Perhaps the docs should be improved?

Yeah, perhaps open up an issue on laravel/docs if you see an area that needs improvement. Thanks!

DB::raw('DROP PROCEDURE IF EXISTS MyProcedure');

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JamborJan picture JamborJan  路  3Comments

lzp819739483 picture lzp819739483  路  3Comments

ghost picture ghost  路  3Comments

iivanov2 picture iivanov2  路  3Comments

Fuzzyma picture Fuzzyma  路  3Comments