2

I’m having issues getting a MySQL connection in PHP using XAMPP and a separate local MySQL server (not the included MariaDB that myphpadmin is running).

I’ve installed MySQL on my computer separately (as I can’t run MariaDB due to work reasons), it works fine in terminal and in MyWorkBench. I’ve updated the port to 3307 to mitigate the risk of it potentially running on the same port as MariaBD (which I have confirmed is actually not running in terminal).

My credentials are correct (as they work in terminal).

$dbobj = new PDO("mysql:host=$dbhost;dbname=$dbdatabase;charset=utf8;port=3307", $dbuser, $dbpwd);

If I try and connect using localhost I get this error: SQLSTATE[HY000] [2002] No such file or directory

If I try and connect using ip 127.0.0.1 I get this error: SQLSTATE[HY000] [2002] Connection refused

Both using port 3307, both work in terminal.

Running XAMPP v. 7.3.10-0, MySQL: 5.7, macOS Catalina 10.15

Yowsa
  • 31
  • 3
  • Does http://127.0.0.1/phpmyadmin/ opens on your system and does it show the $dbdatabase Database in listing? – Amanjot Kaur Nov 12 '19 at 11:33
  • No that doesn't work. And regular localhost/phpmyadmin doesn't work either giving me "Cannot connect: invalid settings", assuming this is since I don't have MariaDB running. – Yowsa Nov 12 '19 at 11:43
  • that means that your IP 127.0.0.1 is not working.. fix that first and then your above code will automatically work – Amanjot Kaur Nov 12 '19 at 11:44
  • please poste your **/etc/phpmyadmin/config.inc.php** or you are on windows the **config.inc.php** where windows stores it –  Nov 18 '19 at 19:23
  • Sorry should've updated with my finding earlier (I have put an answer below now). This is not a phpmyadmin issue. – Yowsa Nov 20 '19 at 08:38

2 Answers2

0

I'll answer my own question incase someone runs into the same issue. I had someone experienced look into this and due to the new XAMPP being run on a virtual machine there is no good solution to my problem. Install MySQL directly on the VM will be too time consuming as it won't have all packages needed etc. So best solution is to either see if work can let me use Maria DB in the interim, or use a different PHP server solution.

Yowsa
  • 31
  • 3
0

As far as I understand you have installed on the same mac box MariaDB and a virtual machine in with you have installed XAMPP. And you tried to make a connection between something running in the VM and something running outside on localhost.

There is something called nmap also for macOS, https://nmap.org/book/inst-macosx.html and you can use it to scan your box and see what services you have on it. Using nmap you could have seen that your not on the same environment. ( ?! )

Anyway I found here some guy telling a very similar story. It looks like he was able to connect the VM with the localhost and it took him a minute.

The next guy is telling about how to access your service on the host machine in your case the database by the hostname setting the network to bridge. <

On macOS you have ifconfig like on Linux, on windows it is called ipconfig, that gives you all information about all adapters you have and the different ip addresses

root@tux:~# ifconfig
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.178.33  netmask 255.255.255.0  broadcast 192.168.178.255
        inet6 fe80::42a8:f0ff:fea2:1e58  prefixlen 64  scopeid 0x20<link>
        ether 40:a8:f0:a2:1e:58  txqueuelen 1000  (Ethernet)
        RX packets 366455797  bytes 41401605218 (38.5 GiB)
        RX errors 0  dropped 65936  overruns 0  frame 0
        TX packets 745920997  bytes 846447546164 (788.3 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 20  memory 0xf7c00000-f7c20000

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Lokale Schleife)
        RX packets 6945633  bytes 1073031154 (1023.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6945633  bytes 1073031154 (1023.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

But you are right better ask the work to accept ... something.