Error connecting to mysql database.

Viewed 10833

It might be a duplicate, but i went through all the solution that are suggested in other posts at stackoverflow but cannot find a solution.

 <?php
$PDO= new PDO('mysql:host= 127.0.0.1; dbname = social_network; charset= utf8', 'root', '' );
$PDO-> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

?>

The error i am having is as follows:

Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2019] Unknown character set in C:\xampp\htdocs\social_network\create_account.php:2 Stack trace: #0 C:\xampp\htdocs\social_network\create_account.php(2): PDO->__construct('mysql:host= 127...', 'root', '') #1 {main} thrown in C:\xampp\htdocs\social_network\create_account.php on line 2

I appreciate your quick asnwer.

4 Answers

you just have to remove the white space in "charset= utf8". So you would have "charset=utf8".

For the charset need to be specific which is being used in XAMPP/WAMP.

You can change charset=utf8 To charset=utf8mb4

Related