diff --git a/classes/Database/PDO/Common.php b/classes/Database/PDO/Common.php index 1cfdc09..0718d05 100644 --- a/classes/Database/PDO/Common.php +++ b/classes/Database/PDO/Common.php @@ -39,7 +39,7 @@ class Database_PDO_Common extends Database_Common protected $attributes = array( PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - PDO::NULL_EMPTY_STRING => true + PDO::NULL_EMPTY_STRING => true, ); /** @@ -55,6 +55,12 @@ class Database_PDO_Common extends Database_Common throw new Exception('Data source name is not defined'); } + if ($this->driver == 'pdo_mysql') + { + // Resolves "Invalid UTF-8 sequence" issues when encoding as JSON + $this->attributes[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES utf8'; + } + if ($this->driver == 'pdo_pgsql') { // This combats a bug: https://bugs.php.net/bug.php?id=62571&edit=1 diff --git a/jar.php b/jar.php index a9f56e0..9b26a45d 100755 --- a/jar.php +++ b/jar.php @@ -1955,7 +1955,7 @@ class Database_PDO_Common extends Database_Common protected $attributes = array( PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - PDO::NULL_EMPTY_STRING => true + PDO::NULL_EMPTY_STRING => true, ); /** @@ -1971,6 +1971,12 @@ class Database_PDO_Common extends Database_Common throw new Exception('Data source name is not defined'); } + if ($this->driver == 'pdo_mysql') + { + // Resolves "Invalid UTF-8 sequence" issues when encoding as JSON + $this->attributes[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES utf8'; + } + if ($this->driver == 'pdo_pgsql') { // This combats a bug: https://bugs.php.net/bug.php?id=62571&edit=1