Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed PDO Connection for MS SQL Server #1021

Merged
merged 2 commits into from Jun 24, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be "===" (triple)

{
$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