What to do when a could not find driver appears when connecting to a DB in a Docker environment

Create a process to connect to DB

<?php
define('DB_NAME', 'Database name');
define('USER_NAME', 'username');
define('USER_PASS', 'password');

try {
  $pdo = new PDO(
    DB_NAME,
    USER_NAME,
    USER_PASS,
    [
      PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
      PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
      PDO::ATTR_EMULATE_PREPARES => false
    ]
  );
} catch (PDOException $e) {
  echo $e->getMessage();
  exit;
}

The following error was output when connecting

could not find driver

It seems that the driver cannot be found, so check the current driver

php -m | grep pdo

# pdo_sqlite

It seems that the cause is that pdo_mysql is not installed, so add processing to DockerFile

FROM php:7.2-fpm
COPY php.ini /usr/local/etc/php/

#add to
RUN docker-php-ext-install pdo_mysql

When I built it again, I was able to connect successfully!

Reference [Laravel] could not find driver in LAMP environment of CentOS

Recommended Posts

What to do when a could not find driver appears when connecting to a DB in a Docker environment
What to do when ‘Could not find’ in any of the sources appears in the development environment with Docker × Rails × RSpec
What to do if Could not find hoge in any of the sources Run `bundle install` to install missing gems. Appears in the docker container
What to do when rails db: seed does not reflect in the database
What to do when routing settings do not work after building Docker environment with Laravel
What to do if you get an error saying "Could not find a JavaScript runtime." When starting rails server
What to do when Rails on Docker does not reflect controller changes in the browser
What to do when an UnsupportedCharsetException occurs in a lightweight JRE
What to do if you get a gcc error in Docker
[Rails] What to do if data is not registered in DB
What to do when the changes in the Servlet are not reflected
What to do when a javax.el.PropertyNotWritableException occurs
[Rails] What to do when the error No database selected and Unknown database appears in db: migrate
What to do when javax.el.ELException: Not a Valid Method Expression: appears when the JSF screen is displayed
What to do when Blocked Host: "host name" appears in Ruby on Rails
What to do when "call'Hoge.connection' to establish a connection" appears on rails c
Notes on what to do when a WebView ClassNotFoundException occurs in JavaFX 12
What to do if Operation not permitted is displayed when you execute a command in the terminal
What I checked when I installed Docker Hub in a Windows 10 home environment but it did not start
What to do when debugging "Source not found"
What to do when IllegalStateException occurs in PlayFramework
When composer install/require in the Docker container, it becomes `Could not find package`
What to do when is invalid because it does not start with a'-'
What to do if you get Could not save master table to file after importing a project in Eclipse
What to do if Command line is too long appears when building a gradle project in Intellij IDEA
[Rails] What to do if you get an error saying "Could not find a JavaScript runtime." When executing the rails s command on Catalina
What I did when I was addicted to the error "Could not find XXX in any of the sources" when I added a Gem and built it
What to do when JSF tags do not become HTML
What to do when a null byte error occurs
What to do when rails creates a 〇〇 2.rb file
What to do if Failure / Error: require File.expand_path ('../ config / environment', __dir__) appears in RSpec
How to deal with errors in Rails s could not find a JavaScript runtime.
What to do when it becomes Unable to find CDI BeanManager.
What to do if you get a java.io.IOException in GlassFish
What to do when Cannot format given Object as a Date in convertDateTime of JSF
What to check when rails db: migration does not pass
[Ruby / Rails] What to do when NoMethodError appears when using a destructive method such as filter!
[Rails Tutorial Chapter 2] What to do when you make a mistake in the column name
How to make a jar with old Hadoop (hadoop-core-0.20.2-cdh3u6) in Gradle: (What to do if you get Could not expand ZIP ..)
What to do when an error (StandardError: An error has occurred, this and all later migrations canceled:) appears in rails db: migrate
What to do when "relation" hibernate_sequence "does not exist" in the ID column of PostgreSQL + JPA
[Programming beginner] What to do when rails s becomes an error in the local development environment
What to do if you get a JNI shared library error when trying to build in Eclipse
[Rails] What to do when rails s does not respond or does not stop
What to do if you get a DISPLAY error in gym.render ()
What to do when you become a Problem During Content Assist
What to do when you run into a docker-compose node_modules problem
What to do if you get an error saying Cannot find a valid baseurl for repo when you use yum -y install docker in a udemy course using CentOS7
What to do when javax.batch.operations.JobStartException occurs
[Rails & Docker & MySQL environment construction] Could not find gem ‘mysql2 (> = 0.4.4, <0.6.0)’ in any of the gem sources listed in your Gemfile.
What to do if you get a groovy warning in Thymeleaf Layout
What to do if the prefix c is not bound in JSP
I tried to build a Firebase application development environment with Docker in 2020
What to do and how to install when an error occurs in DXRuby 1.4.7
What to do if tomcat process remains when tomcat is stopped in eclipse
How to migrate a web application created in a local docker environment to AWS
Do not return when memoizing in Ruby
What to do when undefined method ʻuser_signed_in?'
What to do when Method not found in f: ajax
What to do when you want to delete a migration file that is "NO FILE"
What to do when you think you can't do Groovy-> Java in IntelliJ IDEA CE