Selecting columns
The select()
method in the QueryBuilder
class is used to specify the columns you want to select from a database table while fetching records.
TIP
If you don't specify any columns, the method will select all columns from the table.
Basic usage
You can pass multiple column names as arguments to the select()
method.
php
$query = new QueryBuilder();
$select = $query
->select( 'id', 'name', 'email' );
->from( 'users' )
Using an array
Alternatively, you can pass an array of column names to the select()
method.
php
$query = new QueryBuilder();
$select = $query
->select( ['id', 'name', 'email'] )
->from( 'users' );
Using aliases
You can also use aliases for the columns you want to select.
php
$query = new QueryBuilder();
$select = $query
->select( ['column1' => 'alias1', 'column2' => 'alias2'] )
->from( 'users' );