PDO cannot connect remote mysql server

$conn = new PDO('mysql:hostname=192.168.1.4;dbname=DB_TEST;port=3306','username','password');

should be

$conn = new PDO('mysql:host=192.168.1.4;dbname=DB_TEST;port=3306','username','password');

hostname is invalid for dsn and so PDO is ignoring host and using default, which is localhost


ok i had the same problem too. the solutions is the space between

mysql: host --> this work very well!!!

this way you can connect to remote mysql


The problem on remote PDO mysql conex are on the db string. The correct statement is:

$conn = new PDO('mysql:host=192.168.1.4:3306;dbname=DB_TEST','username','password');