mercredi 27 avril 2022

Unexpected behavior of Laravel 5.4 pluck after migration

Introduction

I have app that runs fine on the following software configurations:

  • Kubuntu 20.04
  • PHP 7.4.29 from Onrej PPA
  • Apache, installed from the distro repos. Using mod_php
  • Laravel 5.4
  • MySQL 5.7 runs from Docker container.

I migrated this app to new OS, Kubuntu 22.04, (I have dual boot on my PC), by copying all the project's files except, vendor and node_modules then I used composer to restore all required dependencies. The software configurations becomes:

  • Kubuntu 22.04
  • PHP 7.4.29 from Onrej PPA > The same
  • Apache, installed from the distro repos. version 2.4.52 Using FPM/FastCGI
  • Laravel 5.4 > The same
  • MySQL ver 8.0.28 installed from the OS repos.

In the migrated app, I had to add modes directive to config/database.php in MySQL connection data to prevent the following fatal error:

dev.ERROR: PDOException: SQLSTATE[42000]: Syntax error or access violation: 1231 Variable 'sql_mode' can't be set to the value of 'NO_AUTO_CREATE_USER' in /home/user/www/app2-vn/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:105

Like the following:

'connections' => [

        'sqlite' => [
            'driver' => 'sqlite',
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
        ],

        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'app2'),
            'username' => env('DB_USERNAME', 'user1'),
            'password' => env('DB_PASSWORD', 'P@55v0'),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true, //true
            'engine' => null,
            'timezone'  => '+02:00',
            'version'  => 8,
            'modes'  => [
          /*  'ONLY_FULL_GROUP_BY',*/
           /* 'STRICT_TRANS_TABLES',*/
          /*  'NO_ZERO_IN_DATE',*/
           /* 'NO_ZERO_DATE',*/
           /* 'ERROR_FOR_DIVISION_BY_ZERO',*/
           /* 'NO_ENGINE_SUBSTITUTION',*/
        ],
        ],

By the way, as shown above, an empty modes just fine to make the application works!

The Issue

I have used pluck like the following:

$eqtypes = \App\Eqtype::get()->pluck('title','id');
dd($eqtypes,\App\Eqtype::get());

In the original app, it works fine with output:

Collection {#1279 ▼
  #items: array:3 [▼
    1 => 'Mold'
    2 => 'Plank'
    3 => 'Neck'
  ]
}

But in the migrated app it returns null for the keys values:

Collection {#1279 ▼
  #items: array:3 [▼
    1 => null
    2 => null
    3 => null
  ]
}

I am very confused, the same code base, the same PHP version and the same framework version, but different result! I tried to look for any compatibility issue between Laravel 5.4 and MySQL 8, but I could not find anything. What do you think the cause of this issue?



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

Aucun commentaire:

Enregistrer un commentaire