framework icon indicating copy to clipboard operation
framework copied to clipboard

New database inspection commands doesn't work in FETCH_ASSOC mode

Open daniser opened this issue 3 years ago • 0 comments

  • Laravel Version: 9.24.0
  • PHP Version: 8.0.18
  • Database Driver & Version: MySQL 8.0.29
  • PDO statement fetch mode: FETCH_ASSOC

Description:

New database inspection commands doesn't work in FETCH_ASSOC mode:

$ artisan db:monitor                                                                                                          
                                                                                                                              
   ErrorException                                                                                                             
                                                                                                                              
  Attempt to read property "Value" on array                                                                                   
                                                                                                                              
  at C:\OpenServer\domains\ttb\vendor\laravel\framework\src\Illuminate\Database\Console\DatabaseInspectionCommand.php:129     
    125▕      */                                                                                                              
    126▕     protected function getConnectionCount(ConnectionInterface $connection)                                           
    127▕     {                                                                                                                
    128▕         return match (class_basename($connection)) {                                                                 
  ➜ 129▕             'MySqlConnection' => (int) $connection->selectOne($connection->raw('show status where variable_name = "th
reads_connected"'))->Value,                                                                                                   
    130▕             'PostgresConnection' => (int) $connection->selectOne('select count(*) as connections from pg_stat_activit
y')->connections,                                                                                                             
    131▕             'SqlServerConnection' => (int) $connection->selectOne('SELECT COUNT(*) connections FROM sys.dm_exec_sessi
ons WHERE status = ?', ['running'])->connections,                                                                             
    132▕             default => null,                                                                                         
    133▕         };                                                                                                           
                                                                                                                              
  1   C:\OpenServer\domains\ttb\vendor\laravel\framework\src\Illuminate\Database\Console\DatabaseInspectionCommand.php:129    
      Illuminate\Foundation\Bootstrap\HandleExceptions::Illuminate\Foundation\Bootstrap\{closure}()                           
                                                                                                                              
  2   C:\OpenServer\domains\ttb\vendor\laravel\framework\src\Illuminate\Database\Console\MonitorCommand.php:103               
      Illuminate\Database\Console\DatabaseInspectionCommand::getConnectionCount()                                             

Steps To Reproduce:

Try to run any of the new database inspection commands (db:monitor, db:show or db:table) with FETCH_ASSOC mode enabled.

Example on how to enable this mode in Laravel 9:

<?php

namespace App\Listeners;

use Illuminate\Database\Events\StatementPrepared;

class StatementPreparedListener
{
    /**
     * Handle the event.
     *
     * @param  StatementPrepared  $event
     * @return void
     */
    public function handle(StatementPrepared $event)
    {
        $event->statement->setFetchMode(\PDO::FETCH_ASSOC);
    }
}

daniser avatar Aug 09 '22 15:08 daniser

Seems a PR was sent in. Thanks all.

driesvints avatar Aug 11 '22 06:08 driesvints