-
Notifications
You must be signed in to change notification settings - Fork 0
execute
Corey Avis edited this page Sep 23, 2026
·
2 revisions
This method acts as the terminal trigger for the query builder. It compiles the internal state into a valid SQL statement and dynamically routes the execution based on the presence of parameter bindings.
If no bindings exist, it bypasses the prepared statement layer entirely for maximum efficiency, making it fully compatible with database administration and utility commands like SHOW, EXPLAIN, and DESCRIBE. If bindings are present, it safely prepares the statement and binds parameters to guarantee SQL injection protection.
execute(): mixed
- Takes no arguments.
(mixed) : Returns the result of the query depending on the SQL command executed and your configured output format:
-
SELECT/SHOW: Returns the data set in your configured output format. (ex. array, json, object, serial, etc.). If the query returns zero rows, it safely maps to an appropriate empty representation based on that format (See: formatData). -
INSERT: Returns theintID of the newly inserted row on success, ortrueif no ID is generated. -
UPDATE/DELETE/REPLACE: Returns anintrepresenting the number of affected rows.
$db->select()->where()->execute();
- Throws an exception if no table has been defined (unless running a raw
query()orshow()statement). - Throws an exception if the compiled SQL string is empty.
- Throws an exception if there is an error with the bindings.
- Throws an exception if there is an unknown error with the execution.
- Triggers a warning if called before any query statements have been defined.