{"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/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Database/Connection.php#L1207-L1243","documentation":"Thrown by the base Connection::escapeBinary() (which is the default implementation). Every concrete driver (MySQL, Postgres, SQLite, SQL Server) overrides escapeBinary() to produce the driver-specific literal; only a base/abstract Connection that has not been subclassed for a driver would hit the fallback.","triggerScenarios":"Calling $connection->escape($value, binary: true) on a Connection that is the base Illuminate\\Database\\Connection rather than a driver-specific subclass, or on a custom Connection subclass that forgot to override escapeBinary().","commonSituations":"A custom driver connection class extending Connection directly without implementing escapeBinary(); using a generic Connection in a polyglot test harness; an unfinished driver adapter package.","solutions":["Use the correct driver-specific Connection class (MySqlConnection, PostgresConnection, etc.) which overrides escapeBinary().","If you wrote a custom Connection subclass, override escapeBinary($value) to produce the driver's binary literal format.","Avoid inline binary escaping entirely; bind the value as a parameter via a prepared statement.","Register a custom driver resolver via Connection::resolver() to map your driver name to a Connection that supports binary."],"exampleFix":"// before\n$conn = new \\Illuminate\\Database\\Connection($pdo, $db, $prefix);\n$conn->escape($blob, binary: true); // throws\n\n// after\n$conn = new \\Illuminate\\Database\\SQLiteConnection($pdo, $db, $prefix);\n$conn->escape($blob, binary: true); // uses SQLite's x'' hex literal","handlingStrategy":"type-guard","validationCode":"if (! method_exists($connection, 'escapeBinary') || (new \\ReflectionMethod($connection, 'escapeBinary'))->getDeclaringClass()->getName() === \\Illuminate\\Database\\Connection::class) {\n    // base class fallback: don't inline-escape; bind instead\n    DB::table('t')->where('col', $binary)->get();\n}","typeGuard":"function supportsBinaryEscape(\\Illuminate\\Database\\Connection $c): bool {\n    return (new \\ReflectionMethod($c, 'escapeBinary'))->getDeclaringClass()->getName()\n        !== \\Illuminate\\Database\\Connection::class;\n}","tryCatchPattern":null,"preventionTips":["Use driver-specific Connection subclasses (MySQL/Postgres/SQLite/SQL Server).","For custom drivers, override escapeBinary() in your Connection subclass.","Prefer parameter binding for binary values over inline escaping.","Register a Connection::resolver() for any custom driver name."],"tags":["escaping","binary","driver","abstraction"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}