| 1234567891011121314151617181920212223242526272829 |
- <?php
- namespace App\Connectors;
- use Illuminate\Database\Connectors\SqlServerConnector;
- /**
- * 信任自签名证书的 SQL Server 连接器
- * 解决 ODBC Driver 18 强制 TLS + 自签名证书导致的 "certificate verify failed" 错误。
- *
- * 在 DSN 末尾追加 ;TrustServerCertificate=1 ,兼容旧版 pdo_sqlsrv (无 SQLSRV_ATTR_TRUST_SERVER_CERTIFICATE 常量)。
- */
- class TrustSqlServerConnector extends SqlServerConnector
- {
- /**
- * {@inheritdoc}
- */
- protected function getDsn(array $config)
- {
- $dsn = parent::getDsn($config);
- // 仅在未包含 TrustServerCertificate 时追加
- if (strpos($dsn, 'TrustServerCertificate') === false) {
- $dsn .= ';TrustServerCertificate=1';
- }
- return $dsn;
- }
- }
|