SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known

First line of the error message describes the error type: “PDOException”. The next line displays PDO::errorInfo, i.e:

  1. SQLSTATE error code (a five characters alphanumeric identifier defined in the ANSI SQL standard).
  2. Driver-specific error code.
  3. Driver-specific error message.
  • “HY000” is a general server error (see Server Error Codes and Messages in MySQL docs).
  • “2002” is MySQL Client Error Code meaning “Can’t connect to local MySQL server through socket” (see (Client Error Codes and Messages in MySQL docs).
  • The driver specific error code and message (“php_network_getaddresses: getaddrinfo failed: Name or service not known”) tell you that PDO is not able to resolve the host name.

The stack trace you attached, line 3, reveals that you did not specify the database connection parameters in the configuration file. The error show up when you test on local, right? You need to update /.env with the actual database connection parameters.

Leave a Comment