Skip to content
Corey Avis edited this page Sep 23, 2026 · 2 revisions

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.

Usage

select(): static
select(array|string ...$columns): static

Parameters

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 a COALESCE(column, ?) function and binds the fallback value.

If no arguments are provided, then the select query will default to selecting all columns (SELECT *).

Return Value

(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.

Method Chaining

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.
    • orderByValue(...) [?]: Prioritizes rows by value.
    • asc(...) [?]: Sort in ascending order.
    • desc(...) [?]: Sort in descending 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.
    • andWhere(...) [?]: Ensures both or multiple conditions must be true to include a row. Supports nested groups.
    • orWhere(...) [?]: Ensures at least one condition must be true to include a row. Supports nested groups.

Examples

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']

Debug Errors

  • No debug errors.

Related Methods

delete | insert | replace | show | update


Home | CoreyDB | Operations

Clone this wiki locally