DB::DBAL

The World's Most Powerful Light-Weight DBAL

Table

table( string $table_name [, string $table_short_name] )

Table() is an important method that determines which database table is used for the query. Whether running a select, an insert, or an update, table must be defined before the query is executed. It is strongly recommended that you start your DB::DBAL query off with the table, such as:

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

If the table you write to is dynamic, you can set up the rest of the query and then add the table later:

1
2
3
4
5
6
7
8
9
$query = DB::MySQL()->select()->where('1=1');
if($var == 'table1') {
$query->table('table1');
} else {
$query->table('table2');
}
$result = $query->fetchOne();

However, for readability, again it is strongly encouraged to start off your query by defining the table.

For convenience with joins, you can also give your table a short name by adding a second parameter in the table() method:

1
DB::MySQL()->table('MyLongTableName', 'shortName');

Note that table is not persistent, and must be set on every query you do.