SQLSTATE[HY000][2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known

喜欢而已 提交于 2019-12-05 03:36:28

Your quotes are all messed up.

$db = new PDO('mysql:host='.DBHOST.';port=8889;dbname='.DBNAME, DBUSER, DBPASS);

I encountered the same Error with this line of code

$dsn = 'mysql:dbname=$dbname;host=$host;port=$port';

and i was able to resolve the error by replacing the single quotes with double quotes as below.

$dsn = "mysql:dbname=$dbname;host=$host;port=$port";

i spent two days looking for solution online and couldn't find it until i decided to do the above changes, and it worked. I still don't understand why it doesn't work with single quotes.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!