Commit 3f567eb7 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Add function to check db encoding is utf8

parent df3a5fb1
......@@ -62,6 +62,27 @@ function db_quote_identifier($identifier) {
return '"' . $identifier . '"';
}
/**
* Check whether the db's default character encoding is utf8
*
* @return bool
*/
function db_is_utf8() {
global $db;
if (!is_a($db, 'ADOConnection')) {
throw new SQLException('Database connection is not available ');
}
if (is_mysql()) {
$result = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
return $result->fields['Value'] == 'utf8';
}
if (is_postgres()) {
$result = $db->Execute("SHOW SERVER_ENCODING");
return $result->fields['server_encoding'] == 'UTF8';
}
return false;
}
/**
* Execute a given sql command string
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment