0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PHPのDB接続の時に、SQLSTATE[HY000] [2002] No such file or directory.と出た時の対応

Last updated at Posted at 2022-10-30

環境

  • PC:Mac
  • サーバー:ロリポップサーバー
  • 言語:PHP8.1.7

内容

ログインフォームなどで、DBに接続しようとすると、

SQLSTATE[HY000] [2002] No such file or directory

というエラーが出た。MySQL接続エラーらしい。

解決策

mysql:の後の空白を消してあげる。

Login.php
$dsn = sprintf('mysql: host=%s; dbname=%s; charset=utf8', $db['host'], $db['dbname']);

消した後

Login.php
$dsn = sprintf('mysql:host=%s; dbname=%s; charset=utf8', $db['host'], $db['dbname']);

これで無事にmysqlに接続ができ、ログインできました。

参考記事

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?