PDO equivalent of mysql_client_encoding ()?

Is there any way in PDO for checking client encoding, like in mysql / mysqli with mysql_client_encoding();?

PHP.net says that you can set the encoding with PDO::setAttribute(), for example:

$db->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");

But how to get the current encoding?

+3
source share
1 answer

There are two different character sets:

To find out the current value of these variables using PDO, you can get the corresponding results SHOW VARIABLES; eg:

$qry = $db->query("SHOW VARIABLES LIKE 'character_set_client'");

mysql_client_encoding() , :

character_set MySQL.

, , .

, MYSQL_ATTR_INIT_COMMAND DSN ( ):

$db = new PDO("mysql:dbname=$db;host=$host;charset=$charset", $user, $password);
+5

All Articles