After an upgrade to El Capitan I'm having issues connecting to MySql. I have a basic PHP file called index.php
with the following code:
<?php
$conn = new mysqli("127.0.0.1", "xxxx", "xxxx");
if ($conn->connect_error) die("Connection failed: " . $conn->connect_error);
echo "Connected successfully";
?>
Now when I visit the page in my browser, I get the following message:
Warning: mysqli::mysqli(): (HY000/2002): Connection refused in /Users/rich/Documents/DESIGN/test/index.php on line 3
Connection failed: Connection refused
I can't understand what's going wrong here. I should mention that I also had this problem on Yosemite before upgrade. The problem began when I wiped my computer to do a fresh install and had to setup Apache and PHP config again. I think something must have been left out of one of the files.
EDIT
I've also tried using localhost
in the connection instead of 127.0.0.1
. That changes the error slightly to:
Warning: mysqli::mysqli(): (HY000/2002): No such file or directory in /Users/rich/Documents/DESIGN/test/index.php on line 4
Connection failed: No such file or directory