PHP Warning: mysqli_connect(): (HY000/2002): Connection refused
In case anyone else comes by this issue, the default port on MAMP for mysql is 8889
, but the port that php expects to use for mysql is 3306
. So you need to open MAMP, go to preferences, and change the MAMP mysql port to 3306
, then restart the mysql server. Now the connection should be successful with host=localhost, user=root, pass=root.
Sometimes you need to include mysql db port id in the server like so.
$serverName = "127.0.0.1:3307";