Is there a way of retrieving the current character set with PDO? I used to have a little test with Mysqli to check if the forced character set was set by retrieving it like
If we run the following MySQL query;
mysql> SELECT COLLATION('foo');
+-----------------------+
| COLLATION('foo') |
+-----------------------+
| utf8_general_ci |
+-----------------------+
1 row in set
So, we can use the following to get the charset
$objCharset = $objPdo->query("SELECT COLLATION('foo')");
echo $objCharset->fetch(PDO::FETCH_NUM)[0]; //Output: utf8_general_ci
You can then go a step further, and use the following (with object injection).
query("SELECT COLLATION('foo')");
return $objCharset->fetch(PDO::FETCH_NUM)[0];
}
}
$objFoo = new foo();
$objPDO = new PDO(...);
echo $objFoo->get_charset($objPDO);