0
Mac Catalina
Mysql server 8.02 community server
phpmyadmin 5.0.2
php 7.47

Phpmyadmin is working fine. See screen capture:

enter image description here

From phpmyadmin, I was able to create a local user and db, both called test on localhost.

However, I am not capable of connecting to it from my php program:

<?php
$db_creds = array();
$db_creds['user'] = 'test';
$db_creds['pwd'] = 'xxxxxxxxx';
$db_creds['name'] = 'test';
$db_creds['host'] = 'localhost';

$mysqli = new mysqli($db_creds['host'], $db_creds['user'], $db_creds['pwd'], $db_creds['name']);

gives me the following error message:

Warning: mysqli::__construct(): (HY000/2002): No such file or directory in /Users/my-mac/Dropbox/joe/development/php/test_2.php on line 8 (last line)

Any ideas?

Dharman
  • 30,962
  • 25
  • 85
  • 135
EastsideDev
  • 6,257
  • 9
  • 59
  • 116
  • 1
    Try changing your `host` to `127.0.0.1` and see if that works? [*Reference*](https://stackoverflow.com/a/20074372/2518525) – Darren Sep 23 '20 at 00:56
  • This seems to work. Any explanation? – EastsideDev Sep 23 '20 at 00:59
  • 3
    Using `127.0.0.1` forces a TCP connection. The default for `locahost` is to try and use a local socket which seems to be set incorrectly for your environment. You can configure the default value via `mysqli.default_socket` or pass in a specific value into the `mysqli` constructor (6th argument) – Phil Sep 23 '20 at 01:16
  • Exactly what @Phil said above - great explanation! – Darren Sep 23 '20 at 02:09

0 Answers0