Skip to content

Commit

Permalink
Merge pull request #1021 from billmn/pdo-sqlserver-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
WanWizard committed Jun 24, 2012
1 parent e3cc64f commit a22e219
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions classes/database/pdo/connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,22 @@ public function connect()
}
catch (\PDOException $e)
{
throw new \Database_Exception($e->getMessage(), $e->getCode(), $e);
$error_code = is_numeric($e->getCode()) ? $e->getCode() : 0;
throw new \Database_Exception($e->getMessage(), $error_code, $e);
}

if ( ! empty($this->_config['charset']))
{
// Set the character set
$this->set_charset($this->_config['charset']);
// Set Charset for SQL Server connection
if (strtolower($this->driver_name()) == 'sqlsrv')
{
$this->_connection->setAttribute(\PDO::SQLSRV_ATTR_ENCODING, \PDO::SQLSRV_ENCODING_SYSTEM);
}
else
{
// Set the character set
$this->set_charset($this->_config['charset']);
}
}
}

Expand All @@ -101,6 +110,15 @@ public function disconnect()
return true;
}

/**
* Get the current PDO Driver name
* @return string
*/
public function driver_name()
{
return $this->_connection->getAttribute(\PDO::ATTR_DRIVER_NAME);
}

public function set_charset($charset)
{
// Make sure the database is connected
Expand Down

0 comments on commit a22e219

Please sign in to comment.