{"record":{"id":"afddae1a57b205f9","repo":"symfony/http-foundation","slug":"urls-without-scheme-are-not-supported-to-configure-the","errorCode":null,"errorMessage":"URLs without scheme are not supported to configure the PdoSessionHandler.","messagePattern":"URLs without scheme are not supported to configure the PdoSessionHandler\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"Session/Storage/Handler/PdoSessionHandler.php","lineNumber":529,"sourceCode":"        $params = parse_url($url);\n\n        if (false === $params) {\n            return $dsnOrUrl; // If the URL is not valid, let's assume it might be a DSN already.\n        }\n\n        $params = array_map('rawurldecode', $params);\n\n        // Override the default username and password. Values passed through options will still win over these in the constructor.\n        if (isset($params['user'])) {\n            $this->username = $params['user'];\n        }\n\n        if (isset($params['pass'])) {\n            $this->password = $params['pass'];\n        }\n\n        if (!isset($params['scheme'])) {\n            throw new \\InvalidArgumentException('URLs without scheme are not supported to configure the PdoSessionHandler.');\n        }\n\n        $driverAliasMap = [\n            'mssql' => 'sqlsrv',\n            'mysql2' => 'mysql', // Amazon RDS, for some weird reason\n            'postgres' => 'pgsql',\n            'postgresql' => 'pgsql',\n            'sqlite3' => 'sqlite',\n        ];\n\n        $driver = $driverAliasMap[$params['scheme']] ?? $params['scheme'];\n\n        // Doctrine DBAL supports passing its internal pdo_* driver names directly too (allowing both dashes and underscores). This allows supporting the same here.\n        if (str_starts_with($driver, 'pdo_') || str_starts_with($driver, 'pdo-')) {\n            $driver = substr($driver, 4);\n        }\n\n        $dsn = null;","sourceCodeStart":511,"sourceCodeEnd":547,"githubUrl":"https://github.com/symfony/http-foundation/blob/5aea19cd678fa4140f6108406f1096de5e9ed6e4/Session/Storage/Handler/PdoSessionHandler.php#L511-L547","documentation":"When the handler receives a URL instead of a raw PDO DSN, buildDsnFromUrl() parses it with parse_url(). If the URL has no scheme (e.g. 'localhost/db' or a bare DSN passed where a URL was expected), the code cannot map it to a PDO driver and throws an InvalidArgumentException.","triggerScenarios":"Passing a connection string/URL without a scheme (e.g. 'database_host/dbname' or missing 'pdo-' prefix style) as the first constructor argument of PdoSessionHandler, so parse_url() yields no 'scheme' key.","commonSituations":"Config mistakes where an env var like DATABASE_URL is empty or truncated; confusing a PDO DSN with the URL form; YAML/env interpolation dropping the scheme part.","solutions":["Ensure the URL includes a scheme, e.g. pdo-mysql://user:pass@host/dbname or mysql://...","If you meant to pass a raw PDO DSN (e.g. 'mysql:host=localhost;dbname=app'), that is supported too — just don't mix formats; verify the env var value","Check the framework session handler config (handler_id / dsn option) so a proper URL is injected"],"exampleFix":"// before\n$handler = new \\PdoSessionHandler('localhost/sessions');\n// after\n$handler = new \\PdoSessionHandler('mysql://user:pass@localhost/sessions');","handlingStrategy":"validation","validationCode":"$url = $_ENV['DATABASE_URL'] ?? '';\nif ($url !== '' && strpbrk(parse_url($url, PHP_URL_SCHEME) ?: '', 'a') === false || parse_url($url, PHP_URL_SCHEME) === false || parse_url($url, PHP_URL_SCHEME) === null) {\n    throw new \\InvalidArgumentException('DATABASE_URL must include a scheme, e.g. mysql://user:pass@host/db');\n}","typeGuard":"function hasScheme(string $url): bool {\n    return is_string(parse_url($url, PHP_URL_SCHEME)) && parse_url($url, PHP_URL_SCHEME) !== '';\n}","tryCatchPattern":"try {\n    $handler = new \\PdoSessionHandler($dsnOrUrl, $options);\n} catch (\\InvalidArgumentException $e) {\n    // log config error: URL/DSN malformed or missing scheme\n}","preventionTips":["Always validate the configured DSN/URL env var includes a scheme at boot","Don't mix raw PDO DSN and URL formats; pick one convention per environment","Add a config-time lint that parses session handler connection strings"],"tags":["dsn","url","sessions","configuration"],"backgroundTag":"invalid-url-format","analyzedSha":"5aea19cd678fa4140f6108406f1096de5e9ed6e4","analyzedAt":"2026-09-13T01:52:22.855Z","contentChangedAt":"2026-09-13T01:52:22.855Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}