Differences between ways to set the charset in Mysql

Asked

Viewed 41 times

0

What is the difference between these 2 ways to set the charset in the communication with the bank?

$pdo = new PDO("mysql:dbname=qualuqer_db;host=localhost;charset=utf8", "root", "");

and

$pdo = new PDO("mysql:dbname=qualuqer_db;host=localhost", "root", "", array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET names utf8"));
  • 1

    There are no differences. The constant MYSQL_ATTR_INIT_COMMAND serves only to inform the PDO, that you want to run that command. Could be, for example, [PDO::MYSQL_ATTR_INIT_COMMAND => "SET sql_mode=''"]

  • @Valdeirpsr Ahh yes, thank you!

  • A vc will use the default charset that is set in the database the other you choose the formatting you want and as @Valdeirpsr said you can set other values, this only "overwrite" the database pattern

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.