jeudi 12 novembre 2020

Why does laravel query showing SQLSTATE[42000]: Syntax error or access violation error?

I'm working with Laravel framework 8.7.1 on Homestead.

I have this query:

  $option_groups = DB::select('select option, opt_icon from dashboard_menu group by option, 
  opt_icon');

When I open the page, I get this error:

  SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'option, opt_icon from dashboard_menu group by option, opt_icon' at line 1 (SQL: select option, opt_icon from dashboard_menu group by option, opt_icon)

What I have tried:

  • I changed strict to false in the config/database.php file, here's my 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' => false,                        
          'engine' => null,
          'options' => extension_loaded('pdo_mysql') ? array_filter([
              PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
          ]) : [],
      ],
    
  • I have run the following commands inside my project:

    $ php artisan config:clear
    
    $ php artisan cache:clear
    
    $ php artisan config:cache
    

But the problem is still the same.

Any ideas why is this happening?

Thank you



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3eOJuiu
via IFTTT

Aucun commentaire:

Enregistrer un commentaire