1

Yeah,

I have the following error:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2005] Unknown MySQL server host '127.0.0.1:3306' (11001)' in C:\xampp\htdocs\php.php:5 Stack trace: #0 C:\xampp\htdocs\php.php(5): PDO->__construct('mysql:host=127....', 'root', 'pass') #1 {main} thrown in C:\xampp\htdocs\php.php on line 5

php.php contains the following:

error_reporting(E_ALL);
ini_set('display_errors', 1);

/* Database Setting */
$db['host'] = '127.0.0.1'; //Mysql's Host
$db['port'] = '3306'; //Mysql's port
$db['user'] = "root"; //Mysql's user
$db['pass'] = 'pass'; //Mysql's password
$db['db'] = "db"; //Mysql's database

$dbh = new PDO('mysql:host='.$db['host'].':'.$db['port'].';dbname='.$db['db'].'', $db['user'], $db['pass']);

I found some other posts but those were with the same error but then with localhost instead of 127.0.0.1 its really weird, can you guys please help me out?

Thanks!

Aaron jonk
  • 31
  • 1
  • 5
  • 1
    Probably your mysql server is not running. Did you tried to restart XAMPP? Did you checked it's control panel with mysql status? – Mcload Jan 12 '18 at 12:29
  • Yes I did @Mcload everything is running, and I can just normally access localhost/phpmyadmin (web panel). – Aaron jonk Jan 12 '18 at 12:37
  • 3
    I'm asking to reopen this post, the reason why it's not working because you specify the port number using this syntax `mysql:host=127.0.0.1:3306;...`, while it should be `mysql:host=127.0.0.1;port:3306;...`, – YouneL Jan 12 '18 at 12:44
  • 1
    That solution was an answer here: https://stackoverflow.com/a/22027089/765899 so the close because of duplicate is true. – Mcload Jan 12 '18 at 12:56

0 Answers0