This forum is no longer active. Please post your questions to our new community site

Forums MAMPStack

error when accessing mysql from PHP

Subscribe to error when accessing mysql from PHP 2 post(s), 2 voice(s)

Avatar silliemunkie 3 post(s)

i get the following error when trying to access my database:

Warning: mysqli::mysqli(): (HY000/2002): Can’t connect to local MySQL server through socket ‘/var/mysql/mysql.sock’ (2) in /- on line 3 Warning: mysqli::query(): Couldn’t fetch mysqli in /- on line 4 Warning: main(): Couldn’t fetch mysqli in /- on line 4

the calling code is:


$mysql = new mysqli(‘localhost’, ‘root’, ‘password’, ‘db’) or die(‘you\’re dead’);
$result = $mysql→query(“SELECT * FROM mytable”) or die($mysql→error);

if($result) {

while($row = $result→fetch_object()) {
$name = $row→name;
# note that this isn’t ideal – to echo out text before the doctype. This is just for example. In a real-world app, we’d echo this info out within the container div.
echo $name . “

I’m sure I am missing a configuration step somewhere, but can’t seem to get the right combination.

thank you,

Avatar Beltrán Rueda Administrator 3,714 post(s)


Could you try to specify the socket in the /php/etc/php.ini file?

mysqli.default_socket = /mysql/tmp/mysql.sock


Forums MAMPStack