Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.2K
Visualizações
Laravel error: Cannot execute queries while other unbuffered queries are active

My Laravel application (version 5.0.33) has suddenly started throwing the following error:

local.ERROR: exception 'PDOException' with message '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.' in vendor/laravel/framework/src/Illuminate/Database/Connection.php:296

Looking at the relevant line in Connection.php, it appears to be already using fetchAll:

 public function select($query, $bindings = array(), $useReadPdo = true)
        {
                return $this->run($query, $bindings, function($me, $query, $bindings) use ($useReadPdo)
                {
                        if ($me->pretending()) return array();

                        // For select statements, we'll simply execute the query and return an array
                        // of the database result set. Each element in the array will be a single
                        // row from the database table, and will either be an array or objects.
                        $statement = $this->getPdoForSelect($useReadPdo)->prepare($query);

                        $statement->execute($me->prepareBindings($bindings));

                        return $statement->fetchAll($me->getFetchMode());
                });
        }

I also added the following to my config/database.php:

'options' => [ PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true ]

But I'm still getting the same error. This application has been working correctly for years, and I hadn't made any changes to the code, so I don't know why this suddenly stared happening. I'm also new to Laravel and didn't write the original code, so I'm not even sure where to start debugging the issue. Can anyone help?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I had the same problem with a query in package datatable yajra/laravel-datatables in hosting server, changing the charset to 'charset' => 'utf8mb4', collation 'collation' => 'utf8mb4_unicode_ci' and some options work with me, full config:

'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => array(
                PDO::ATTR_EMULATE_PREPARES => true,
                PDO::MYSQL_ATTR_LOCAL_INFILE => true,
                PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true
            ),
        ],

ref : Laravel and MemSQL columnstore, unbuffered queries are active and https://www.eversql.com/mysql-utf8-vs-utf8mb4-whats-the-difference-between-utf8-and-utf8mb4/

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda