Check read and write works after changing any DB settings

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the databases category.

Last Updated: 2024-04-25

I needed to change the PDO (PHP data objects) settings in the Project S mysql database for a Laravel project. I set them to the following (no need to read in detail):

'mysql' => [
  'driver' => 'mysql',
  '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'    => [PDO::MYSQL_ATTR_LOCAL_INFILE=>true],
]

After changing them, the app booted and I refreshed the page. Because the data loaded on page correctly, I concluded the settings change was successful and pushed to staging.

However, later that day, I noticed something distressing: Although I was able to read from the DB, I was unable to write. I.e. the settings did not work.

Lesson

If you change anything do with the database settings, ensure both reading and writing still work. To be honest, the best way to achieve this (and more) is just having and running integration tests.