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

[10.x] Ignore MSSQL exception about PDO::ATTR_STRINGIFY_FETCHES #48158

Closed
wants to merge 1 commit into from
Closed
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
33 changes: 33 additions & 0 deletions src/Illuminate/Database/Connectors/SqlServerConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Arr;
use PDO;
use PDOException;

class SqlServerConnector extends Connector implements ConnectorInterface
{
Expand Down Expand Up @@ -36,6 +37,38 @@ public function connect(array $config)
return $connection;
}

/**
* Create a new PDO connection instance.
*
* @param string $dsn
* @param string $username
* @param string $password
* @param array $options
* @return \PDO
*/
protected function createPdoConnection($dsn, $username, $password, $options)
{
// The MSSQL extension is throwing an exception saying the attribute
// `PDO::ATTR_STRINGIFY_FETCHES` is unknown. This wasn't the case
// before. We'll ignore the error until the hotfix is released.

if (! is_null($stringifyFetches = $options[PDO::ATTR_STRINGIFY_FETCHES] ?? null)) {
unset($options[PDO::ATTR_STRINGIFY_FETCHES]);
}

$pdo = parent::createPdoConnection($dsn, $username, $password, $options);

if (! is_null($stringifyFetches)) {
try {
$pdo->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, $stringifyFetches);
} catch (PDOException $e) {
//
}
}

return $pdo;
}

/**
* Set the connection transaction isolation level.
*
Expand Down