-
Notifications
You must be signed in to change notification settings - Fork 0
executeRaw
Corey Avis edited this page Sep 23, 2026
·
2 revisions
Executes a direct SQL query against the database without parameter binding. Returns a result set for read operations or a boolean for write operations. Use this for system-level commands and non-parameterized queries.
📌 Unlike the query builder methods,
executeRawtriggers the database call immediately. Do not chain anexecutemethod at the end of this call.
executeRaw(string $sql): mixed
sql (string) : The SQL statement to run against the database.
(mixed)
: Returns a dataset on success for select-type queries, or true on success and false on failure.
$db->executeRaw('SELECT @@default_storage_engine AS engine');
While both methods allow you to pass custom SQL strings, they handle execution and data manipulation differently.
-
executeRaw(): Designed for fast, immediate execution. It cannot be chained with modifiers and bypasses the internal query builder entirely. Ideal for system-level operations. -
query(): Designed for deferred execution. It starts a chain that allows you to attach modifiers likefilter()andoutput()to format your data, requiring a finalexecute()call to trigger the database.
- Throws an exception if there is an error with the execution.