DB::DBAL

The World's Most Powerful Light-Weight DBAL

Select

select( [ string $arg1, string $arg2, ...] )

The select() method allows you to determine which columns are retrieved in your query. If no columns are placed in the select statement, the method will default to select *, selecting all columns from the table(s) queried.

1
DB::MySQL()->table('myTable')->select(); // select *

You can enter the columns as either a single argument, or in multiple arguments:

1
2
3
4
5
DB::MySQL()->table('myTable')->select('column1, column2, column3');
// is the same as
DB::MySQL()->table('myTable')->select('column1', 'column2', 'column3');

To select columns from specific tables, simply prepend “tableName.” to the column unless the database syntax requires otherwise. For example:

1
2
3
4
5
6
7
8
9
// As a single argument:
DB::MySQL()->table('myTable')
->join('myOtherTable', 'myMatchColumn')
->select('myTable.column1, myOtherTable.column2');
// Or using separate arguments:
DB::MySQL()->table('myTable')
->join('myOtherTable', 'myMatchColumn')
->select('myTable.column1', 'myOtherTable.column2');

To assign aliases to your columns, simply add the appropriate database syntax immediately after the column, such as:

1
2
3
4
5
// Single Argument:
DB::MySQL()->table('myTable')->select('column1 as item1, column2, column3');
// Multiple Arguments:
DB::MySQL()->table('myTable')->select('column1 as item1', 'column2', 'column3');