{"record":{"id":"d27205ead82bd63b","repo":"laravel/framework","slug":"the-database-connection-does-not-support-escaping-d27205","errorCode":null,"errorMessage":"The database connection does not support escaping binary values.","messagePattern":"The database connection does not support escaping binary values\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Connection.php","lineNumber":1225,"sourceCode":"     * @param  bool  $value\n     * @return string\n     */\n    protected function escapeBool($value)\n    {\n        return $value ? '1' : '0';\n    }\n\n    /**\n     * Escape a binary value for safe SQL embedding.\n     *\n     * @param  string  $value\n     * @return string\n     *\n     * @throws \\RuntimeException\n     */\n    protected function escapeBinary($value)\n    {\n        throw new RuntimeException('The database connection does not support escaping binary values.');\n    }\n\n    /**\n     * Determine if the database connection has modified any database records.\n     *\n     * @return bool\n     */\n    public function hasModifiedRecords()\n    {\n        return $this->recordsModified;\n    }\n\n    /**\n     * Indicate if any records have been modified.\n     *\n     * @param  bool  $value\n     * @return void\n     */","sourceCodeStart":1207,"sourceCodeEnd":1243,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Connection.php#L1207-L1243","documentation":"Thrown by the base Connection::escapeBinary(), which is a deliberate stub. The framework expects each concrete driver to override escapeBinary() to emit the correct binary-literal syntax for its RDBMS (MySQL x'..' hex, Postgres bytea '\\x..' , SQL Server 0x..). Calling escape($value, true) on a connection whose driver did not override it hits the stub.","triggerScenarios":"Calling $connection->escape($binary, true) on a base Connection or a custom Connection subclass that does not override escapeBinary(); using a fake SQLite connection in tests that subclasses Connection without overriding escapeBinary.","commonSituations":"Custom Connection subclasses that omit the escapeBinary override; tests using a minimal Connection double; calling escape with binary flag on an unsupported/aggregated connection.","solutions":["Use the concrete driver connection (MySqlConnection/PostgresConnection/SqlServerConnection), which override escapeBinary().","If you wrote a custom Connection subclass, implement escapeBinary($value) to return the correct literal for your driver.","Prefer parameter binding over literal escaping for binary values: ->where('col', '=', $binary).","Store binary via a model cast / BLOB binding so the driver handles encoding."],"exampleFix":"// before\n$conn = new class($pdo, $db, '') extends \\Illuminate\\Database\\Connection {};\n$conn->escape($bytes, true);\n\n// after\n$conn = new \\Illuminate\\Database\\MySqlConnection($pdo, $db, '');\n$conn->escape($bytes, true);","handlingStrategy":"type-guard","validationCode":"$conn = DB::connection();\nif ($conn instanceof \\Illuminate\\Database\\MySqlConnection\n || $conn instanceof \\Illuminate\\Database\\PostgresConnection\n || $conn instanceof \\Illuminate\\Database\\SqlServerConnection) {\n    $sql = $conn->escape($bytes, true);\n} else {\n    throw new \\LogicException('Current connection does not override escapeBinary().');\n}","typeGuard":"function supportsBinaryEscape(\\Illuminate\\Database\\Connection $c): bool {\n    return $c instanceof \\Illuminate\\Database\\MySqlConnection\n        || $c instanceof \\Illuminate\\Database\\PostgresConnection\n        || $c instanceof \\Illuminate\\Database\\SqlServerConnection\n        || $c instanceof \\Illuminate\\Database\\MariaDbConnection;\n}","tryCatchPattern":"try {\n    $sql = $connection->escape($bytes, true);\n} catch (\\RuntimeException $e) {\n    // fall back to parameter binding which all drivers handle\n    $connection->insert('insert into blobs (data) values (?)', [$bytes]);\n}","preventionTips":["Use parameter binding for binary values instead of literal escaping.","Confirm your custom Connection subclass overrides escapeBinary() if you need literal binary SQL.","Default to concrete driver connections (MySql/Postgres/SqlServer) for binary support."],"tags":["database","escaping","binary","driver","laravel"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}