Added a flag to resolve UTF-8 sequence errors

This commit is contained in:
Josh Sherman 2013-02-26 16:07:14 -05:00
parent d25b042d8e
commit 07d00289a1
2 changed files with 14 additions and 2 deletions

View file

@ -39,7 +39,7 @@ class Database_PDO_Common extends Database_Common
protected $attributes = array( protected $attributes = array(
PDO::ATTR_PERSISTENT => true, PDO::ATTR_PERSISTENT => true,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, 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'); 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') if ($this->driver == 'pdo_pgsql')
{ {
// This combats a bug: https://bugs.php.net/bug.php?id=62571&edit=1 // This combats a bug: https://bugs.php.net/bug.php?id=62571&edit=1

View file

@ -1955,7 +1955,7 @@ class Database_PDO_Common extends Database_Common
protected $attributes = array( protected $attributes = array(
PDO::ATTR_PERSISTENT => true, PDO::ATTR_PERSISTENT => true,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, 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'); 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') if ($this->driver == 'pdo_pgsql')
{ {
// This combats a bug: https://bugs.php.net/bug.php?id=62571&edit=1 // This combats a bug: https://bugs.php.net/bug.php?id=62571&edit=1