Yazan
Yazan

Reputation: 71

Unknown Database when calling PDO(), for a MySQL database created on phpMyAdmin using WAMPServer 3.2.0

I created a MySQL database 'testdatabase' using phpMyAdmin associated to installed WAMPServer v-3.2.0, however, when i try connecting to the database using php as listed in my code below:

$conn = new PDO("mysql:host=$servername;dbname=testdatabase", $username, $password);

the exception getMessage and getTraceAsString prints the following error message:

Connection failed: SQLSTATE[HY000] [1049] Unknown database 'testdatabase'#0 C:\wamp64\www\TestProject\test.php(10): PDO->__construct('mysql:host=loca...', 'root', NULL) #1 {main}

Note: when trying to connect to system defined databases such as "mysql" and "information_schema" it echoes "Connected successfully".

Why can't PDO recognize "testdatabase"?

Upvotes: 0

Views: 1158

Answers (1)

Thibault Dumas
Thibault Dumas

Reputation: 1070

Check if there is the port in your $servername, like localhost:8080

Upvotes: -2

Related Questions