{
  "id": "php/pdo-odbc-connection-string-malformed",
  "signature": "PDOException: SQLSTATE[IM002] SQLDriverConnect: 0 [unixODBC][Driver Manager]Data source name not found, and no default driver specified in /var/www/app/src/Database/OdbcConnector.php on line 21",
  "signature_zh": "PDOException：SQLSTATE[IM002] SQLDriverConnect：0 [unixODBC][驱动程序管理器]未找到数据源名称，且未指定默认驱动程序，位于 /var/www/app/src/Database/OdbcConnector.php 第 21 行",
  "regex": "SQLSTATE\\[IM002\\] SQLDriverConnect: 0 \\[unixODBC\\]\\[Driver Manager\\]Data source name not found",
  "domain": "php",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "ODBC connection string references a DSN that is not defined in odbc.ini or /etc/odbc.ini, or the required ODBC driver is not installed/configured on the system.",
  "root_cause_type": "generic",
  "root_cause_zh": "ODBC 连接字符串引用了未在 odbc.ini 或 /etc/odbc.ini 中定义的 DSN，或者系统上未安装/配置所需的 ODBC 驱动程序。",
  "versions": [
    {
      "version": "PHP 8.1.30",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "PHP 8.2.18",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "unixODBC 2.3.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Installing only the ODBC driver (e.g., psqlodbc for PostgreSQL) without configuring the DSN in odbc.ini still results in the same error because the driver is not associated with a DSN name.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Using a DSN name with spaces or special characters without quoting it in the connection string causes the driver manager to parse it incorrectly.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Verify DSN configuration: odbcinst -j shows config files; check /etc/odbc.ini for [MyDSN] section with Driver= and Server= entries. Add missing DSN: echo -e '[MyDSN]\\nDriver=PostgreSQL Unicode\\nServer=localhost\\nPort=5432\\nDatabase=mydb' >> /etc/odbc.ini",
      "success_rate": 0.9,
      "how": "Verify DSN configuration: odbcinst -j shows config files; check /etc/odbc.ini for [MyDSN] section with Driver= and Server= entries. Add missing DSN: echo -e '[MyDSN]\\nDriver=PostgreSQL Unicode\\nServer=localhost\\nPort=5432\\nDatabase=mydb' >> /etc/odbc.ini",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a full connection string without DSN: $pdo = new PDO('odbc:Driver={PostgreSQL Unicode};Server=localhost;Port=5432;Database=mydb;Uid=user;Pwd=pass;');",
      "success_rate": 0.85,
      "how": "Use a full connection string without DSN: $pdo = new PDO('odbc:Driver={PostgreSQL Unicode};Server=localhost;Port=5432;Database=mydb;Uid=user;Pwd=pass;');",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Verify DSN configuration: odbcinst -j shows config files; check /etc/odbc.ini for [MyDSN] section with Driver= and Server= entries. Add missing DSN: echo -e '[MyDSN]\\nDriver=PostgreSQL Unicode\\nServer=localhost\\nPort=5432\\nDatabase=mydb' >> /etc/odbc.ini",
    "Use a full connection string without DSN: $pdo = new PDO('odbc:Driver={PostgreSQL Unicode};Server=localhost;Port=5432;Database=mydb;Uid=user;Pwd=pass;');"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.php.net/manual/en/ref.pdo-odbc.connection.php",
  "official_doc_section": null,
  "error_code": "IM002",
  "verification_tier": "ai_generated",
  "confidence": 0.86,
  "fix_success_rate": 0.87,
  "resolvable": "partial",
  "first_seen": "2024-07-22",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}