Is there a way to get a defined encoding for a MySQL table in PHP?


I see I can get a MySQL database defined encoding in PHP using the function mysql_client_encoding(...), but is there a way to get a MySQL table defined encoding in PHP?

I see no easy way to retrieve this info. The best I could do is to do a "SHOW CREATE TABLE ;" and parse the answer:


$link = mysql_connect('localhost', 'account', 'passwd');

$q = mysql_query('show create table my_table;');
$row = mysql_fetch_assoc($q);

preg_match("/CHARSET=(.*)/", $row['Create Table'], $matched);
echo "Table was created with charset " . $matched[1];

Which gives me:

Table was created with charset utf8

Note that charset may not be present if your table was not created with this info.