Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
736 views
in Technique[技术] by (71.8m points)

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

I download from https://github.com/luciddreamz/laravel Laravel for openshift then upload over my repository over github. This code for connect to database not work. The problem is that load variable from .env file that locate in root of project

for solve this problem change.env

# local environment only
#   for production, see .openshift/.env

APP_ENV=APPLICATION_ENV
APP_DEBUG=true
APP_URL=OPENSHIFT_APP_DNS
APP_KEY=OPENSHIFT_SECRET_TOKEN

DB_DRIVER=mysql
DB_HOST=OPENSHIFT_MYSQL_DB_HOST
DB_PORT=OPENSHIFT_MYSQL_DB_PORT
DB_DATABASE=OPENSHIFT_APP_NAME
DB_USERNAME=OPENSHIFT_MYSQL_DB_USERNAME 
DB_PASSWORD=OPENSHIFT_MYSQL_DB_PASSWORD

CACHE_DRIVER=apc
SESSION_DRIVER=file

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

createConnection('mysql:host=OPENSHIFT_MYSQL_DB_HOST;port=OPENSHIFT_MYSQL_DB_PORT;dbname=OPENSHIFT_APP_NAME', 
array('driver' => 'mysql', 
      'host' => 'OPENSHIFT_MYSQL_DB_HOST', 
      'port' => 'OPENSHIFT_MYSQL_DB_PORT', 
      'database' => 'OPENSHIFT_APP_NAME', 
      'username' => 'OPENSHIFT_MYSQL_DB_USERNAME', 
      'password' => 'OPENSHIFT_MYSQL_DB_PASSWORD', 
      'charset' => 'utf8',  
      'collation' => 'utf8_unicode_ci', 
      'prefix' => '', 
      'strict' => false, 
      'name' => 'mysql'), 
array('0', '2', '0', false, '0')) in MySqlConnector.php line 20

error message

question from:https://stackoverflow.com/questions/30182984/sqlstatehy000-2002-php-network-getaddresses-getaddrinfo-failed-name-or-ser

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...