{"record":{"id":"9549ed2c154c35fa","repo":"yiisoft/yii2","slug":"failed-to-prepare-sql-sql","errorCode":null,"errorMessage":"{}\nFailed to prepare SQL: $sql","messagePattern":"(.+?)\nFailed to prepare SQL: \\$sql","errorType":"exception","errorClass":"yii\\db\\Exception","httpStatus":null,"severity":"error","filePath":"framework/db/Command.php","lineNumber":273,"sourceCode":"        }\n\n        if ($this->db->getTransaction()) {\n            // master is in a transaction. use the same connection.\n            $forRead = false;\n        }\n        if ($forRead || $forRead === null && $this->db->getSchema()->isReadQuery($sql)) {\n            $pdo = $this->db->getSlavePdo(true);\n        } else {\n            $pdo = $this->db->getMasterPdo();\n        }\n\n        try {\n            $this->pdoStatement = $pdo->prepare($sql);\n            $this->bindPendingParams();\n        } catch (\\Exception $e) {\n            $message = $e->getMessage() . \"\\nFailed to prepare SQL: $sql\";\n            $errorInfo = $e instanceof \\PDOException ? $e->errorInfo : null;\n            throw new Exception($message, $errorInfo, $e->getCode(), $e);\n        } catch (\\Throwable $e) {\n            $message = $e->getMessage() . \"\\nFailed to prepare SQL: $sql\";\n            throw new Exception($message, null, $e->getCode(), $e);\n        }\n    }\n\n    /**\n     * Cancels the execution of the SQL statement.\n     * This method mainly sets [[pdoStatement]] to be null.\n     */\n    public function cancel()\n    {\n        $this->pdoStatement = null;\n    }\n\n    /**\n     * Binds a parameter to the SQL statement to be executed.\n     * @param string|int $name parameter identifier. For a prepared statement","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/db/Command.php#L255-L291","documentation":"Error \"{}\nFailed to prepare SQL: $sql\" thrown in yiisoft/yii2.","triggerScenarios":"Thrown at framework/db/Command.php:273 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}