-
Notifications
You must be signed in to change notification settings - Fork 0
select
Defines the query type as a SELECT statement and specifies the columns to be retrieved.
📌 Execution Required: This method only constructs the SQL statement. You must terminate the method chain with
->execute()to actually run the query against the database or->preview()to view the sql code.
select(): static
select(array|string ...$columns): static
columns (array|string) : A list of string column names, or an array containing column definitions. ^(optional)^
- When providing strings or a sequential array: Items are treated as standard column names.
- When providing an associative array (
'column' => 'fallback'): Wraps the column key in aCOALESCE(column, ?)function and binds the fallback value.
If no arguments are provided, then the
selectquery will default to selecting all columns (SELECT *).
(static) : Returns the current instance to allow for method chaining.
NOTE: This method does not execute the query immediately. You must chain the
execute()method at the end of your chain to run the query against the database.Upon successful execution, the
execute()method returns the selected data from the database.
Before calling execute(), you can chain the following modifiers to customize your results:
-
between(...)[?]: Filters data within an inclusive range. -
in(...)[?]: Filters data that matches any value in a specified list.-
notIn(...)[?]: Filters data that excludes everything in a specified list
-
-
like(...)[?]: Filters data by matching a specific text pattern using wildcards. -
limit(...)[?]: Limit number of affected rows. -
offset(...)[?]: Limit offset. -
order(...)[?]: Defines the sort order. -
output(...)[?]: Defines the structure of the output data (e.g., Array, JSON, Object, Serial). -
where(...)[?]: Filters query results by applying specific conditions to rows.
Default (No arguments)
$db->select()->where()->execute();
// Result: SELECT * FROM `table` WHERE 1
String Arguments (Sequential)
$db->select('item', 'qty')->where()->execute();
// Result: SELECT `item`, `qty` FROM `table` WHERE 1
Sequential Array Argument
$db->select(['item', 'qty'])->where()->execute();
// Result: SELECT `item`, `qty` FROM `table` WHERE 1
Associative Array Argument (COALESCE)
$db->select(['item', 'qty' => 'No value'])->where()->execute();
// Result: SELECT `item`, COALESCE(`qty`, ?) FROM `table` WHERE 1
// Bindings: ['No value']
- No debug errors.
delete | insert | replace | show | update
Home | CoreyDB | Operations