mysql - PHP Connection failed: SQLSTATE[HY000] [2002] Connection refused -


the situation this, trying use php connection connect mysql database on phpmyadmin. nothing fancy connection trying see whether connection successful or not. using mamp host database, connection trying use this:

<?php $servername = "127.0.0.1"; $username = "root"; $password = "root";  try {     $conn = new pdo("mysql:host=$servername;dbname=appdatabase", $username, $password);     // set pdo error mode exception     $conn->setattribute(pdo::attr_errmode, pdo::errmode_exception);     echo "connected successfully";  } catch(pdoexception $e) {     echo "connection failed: " . $e->getmessage(); } ?> 

i have been using postman test see if connection working, keep receiving error message:

connection failed: sqlstate[hy000] [2002] connection refused

before receiving error message of:

connection failed: sqlstate[hy000] [2002] no such file or directory

this because had set servername localhost, through changing ip address has given me connection refused , have no idea wrong.

any regarding appreciated, thanks.

i found reason why connection not working, because connection trying connect port 8888, when needed connect port 8889.

$conn = new pdo("mysql:host=$servername;port=8889;dbname=appdatabase", $username, $password);  

this fixed problem, although changing server name localhost still gives error.

connection failed: sqlstate[hy000] [2002] no such file or directory

but connects when ip address entered server name.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -