{
  "id": "php/pdo-sqlsrv-connection-failure",
  "signature": "SQLSTATE[08001]: [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Error code 0x2746",
  "signature_zh": "SQLSTATE[08001]：[Microsoft][ODBC Driver 17 for SQL Server]TCP 提供程序：错误代码 0x2746",
  "regex": "SQLSTATE\\[08001\\]: \\[Microsoft\\]\\[ODBC Driver 17 for SQL Server\\]TCP Provider: Error code 0x2746",
  "domain": "php",
  "category": "network_error",
  "subcategory": null,
  "root_cause": "The PHP PDO_SQLSRV connection fails due to TLS protocol mismatch between the client ODBC driver and the SQL Server, often after SQL Server disables older TLS versions (e.g., TLS 1.0/1.1) or the client lacks a required cipher suite.",
  "root_cause_type": "generic",
  "root_cause_zh": "PHP PDO_SQLSRV 连接失败，原因是客户端 ODBC 驱动与 SQL Server 之间的 TLS 协议不匹配，常见于 SQL Server 禁用了较旧的 TLS 版本（如 TLS 1.0/1.1）或客户端缺少所需的密码套件。",
  "versions": [
    {
      "version": "php 8.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "php 8.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "php 8.3",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "ODBC Driver 17 for SQL Server",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "ODBC Driver 18 for SQL Server",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Reinstalling the ODBC driver without updating TLS settings",
      "why_fails": "The default ODBC driver installation may still use outdated TLS configurations; reinstalling alone does not change the TLS protocol negotiation behavior.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Downgrading PHP to an older version (e.g., 7.4)",
      "why_fails": "The TLS handshake failure is not a PHP version issue but a driver-level configuration problem; downgrading PHP does not alter the ODBC driver's TLS behavior.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Update the ODBC driver to version 18 and configure TLS settings in the connection string: `$conn = new PDO('sqlsrv:Server=host;Database=db;Encrypt=yes;TrustServerCertificate=yes;LoginTimeout=30;', $user, $pass);`",
      "success_rate": 0.85,
      "how": "Update the ODBC driver to version 18 and configure TLS settings in the connection string: `$conn = new PDO('sqlsrv:Server=host;Database=db;Encrypt=yes;TrustServerCertificate=yes;LoginTimeout=30;', $user, $pass);`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Add `'CryptoProtocolVersion' => 'TLSv1.2'` to the connection string or set the environment variable `ODBCSYSINI` to point to a custom `odbc.ini` with `CryptoProtocolVersion=TLSv1.2`.",
      "success_rate": 0.8,
      "how": "Add `'CryptoProtocolVersion' => 'TLSv1.2'` to the connection string or set the environment variable `ODBCSYSINI` to point to a custom `odbc.ini` with `CryptoProtocolVersion=TLSv1.2`.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Update the ODBC driver to version 18 and configure TLS settings in the connection string: `$conn = new PDO('sqlsrv:Server=host;Database=db;Encrypt=yes;TrustServerCertificate=yes;LoginTimeout=30;', $user, $pass);`",
    "Add `'CryptoProtocolVersion' => 'TLSv1.2'` to the connection string or set the environment variable `ODBCSYSINI` to point to a custom `odbc.ini` with `CryptoProtocolVersion=TLSv1.2`."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://learn.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server",
  "official_doc_section": null,
  "error_code": "08001",
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.82,
  "resolvable": "partial",
  "first_seen": "2023-09-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}