Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDO connect does not work

Tags:

php

pdo

I try connect to mysql DB with PDO, but does not work. i write:

 $db = new PDO('mysql:dbname=test;host=localhost','user','pass');

returns error:

 Warning: PDO::__construct() [pdo.--construct]: [2002] No connection could be made because
 the target machine actively refused it.

please tell me , wath the PDO wants to?

phpversion: 5.3.9

host: local computer, (server - "usbwebserver")

like image 490
ოთო შავაძე Avatar asked Feb 10 '26 15:02

ოთო შავაძე


1 Answers

It's a port problem. USBwebsever uses mysql port 3307 instead of 3306, so use $db = new PDO('mysql:dbname=test;host=localhost:3307','user','pass');

like image 79
B. Schuurman Avatar answered Feb 17 '26 11:02

B. Schuurman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!