LoginSignup
0
1

More than 1 year has passed since last update.

CentOS Stream 8にPHP PDOのMySQLドライバをインストールする手順

Last updated at Posted at 2022-06-17
../

CentOS Stream 8でMySQLをインストールし、PHPからアクセスを試みるが、PDOの接続で「could not find driver」のエラーが出た。

could not find driver
Uncaught TypeError: Return value of PersistenceBase::pdo() 
must be an instance of PDO, null returned in ...

MySQLコンソールで接続できることは確認し、dsnやuser/passwordを間違えていないことは確認済み。

// dsn = mysql:dbname=test;host=localhost;port=3306;charset=utf8
// user = root
// password = xxx

$ mysql -uroot -p test
enter password: xxx

MySQLドライバは個別にインストールする必要があるということが分かった。初期状態ではpdo_sqliteしか入っていない。SQLiteは、非常に軽いオープンソースのDBMSらしい。

MySQLドライバ(pdo_mysql)を追加でインストールした。

$ php -m | grep pdo
pdo_sqlite

$ dnf install php-mysqlnd
php-mysqlnd  x86_64  7.4.19-2.module_el8.6.0+1075+ab70be85  appstream   193 k

$ php -m | grep pdo
pdo_mysql
pdo_sqlite

PHPからPDOで接続できるようになった。

../
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1