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
Fixed PDO Connection for MS SQL Server
  • Loading branch information
frankdejonge committed Jun 24, 2012
2 parents 608d48b + 5ad870e commit 0fcd6c5
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions classes/database/pdo/connection.php
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 0fcd6c5

Please sign in to comment.