# 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

- **ID:** `php/pdo-odbc-connection-string-malformed`
- **Domain:** php
- **Category:** config_error
- **Error Code:** `IM002`
- **Verification:** ai_generated
- **Fix Rate:** 87%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| PHP 8.1.30 | active | — | — |
| PHP 8.2.18 | active | — | — |
| unixODBC 2.3.12 | active | — | — |

## Workarounds

1. **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** (90% success)
   ```
   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
   ```
2. **Use a full connection string without DSN: $pdo = new PDO('odbc:Driver={PostgreSQL Unicode};Server=localhost;Port=5432;Database=mydb;Uid=user;Pwd=pass;');** (85% success)
   ```
   Use a full connection string without DSN: $pdo = new PDO('odbc:Driver={PostgreSQL Unicode};Server=localhost;Port=5432;Database=mydb;Uid=user;Pwd=pass;');
   ```

## Dead Ends

- **** — 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. (75% fail)
- **** — Using a DSN name with spaces or special characters without quoting it in the connection string causes the driver manager to parse it incorrectly. (60% fail)
