Repository navigation
selectAs
Defines the query type as a SELECT statement using an alias (AS), with optional string concatenation utilizing CONCAT() or CONCAT_WS().
📌 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.
selectAs(string $column, string $as, string ...$concat): static
column (string) : The primary column name or value to be selected or used as the starting point for concatenation.
as (string) : The alias name given to the selected column or concatenated result.
concat (string) : Additional column names or literal string values to concatenate with the primary $column. ^(optional)^
If
$concatis provided, the method automatically merges$columnand$concatinto an array, identifies valid column names to backtick wrap, treats invalid column names as raw string variables, and compiles them into a SQL concatenation function.
- If the
glueconfiguration is empty, it compiles usingCONCAT().- If the
glueconfiguration is populated, it compiles usingCONCAT_WS()using the configured glue value as the separator. (Default glue: ' ' (space))
(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.
Standard Alias (No concatenation)
$db->selectAs('user_id', 'id')->execute();
// Result: SELECT `user_id` AS `id` FROM `table`
With Concatenation (When glue is empty: '' or null)
$db->setConfig('glue', null);
$db->selectAs('Qty: ', 'qty', 'quantity')->execute();
// Result: SELECT CONCAT('Qty: ', `quantity`) AS `qty` FROM `table`
// qty = Qty: quantity
$db->selectAs('first_name', 'full_name', ' ', 'last_name')->execute();
// Result: SELECT CONCAT(`first_name`, ' ', `last_name`) AS `full_name` FROM `table`
// full_name = first_name last_name
With Concatenation (When glue is active)
$db->selectAs('first_name', 'full_name', 'last_name')->execute();
// Result: SELECT CONCAT_WS(' ', `first_name`, `last_name`) AS `full_name` FROM `table`
// full_name = first_name last_name
$db->setConfig('glue', ', ');
$db->selectAs('last_name', 'full_name', 'first_name')->execute();
// Result: SELECT CONCAT_WS(', ', `last_name`, `first_name`) AS `full_name` FROM `table`
// full_name = last_name, first_name
| Config Key | Default Value | Allowed Values | Description |
|---|---|---|---|
| glue | ' ' (space) | string | The separator used for string concatenation. |
NOTE: If set to an empty string or null, the method falls back to a standard CONCAT()
|
- No debug errors.
Home | CoreyDB | Operations