DB::DBAL

The World's Most Powerful Light-Weight DBAL

FetchAll

fetchAll( void )

The fetchAll() method is used to retrieve all records back from a query. This is the equivalent of using the removeLimit() and the fetch() method.

1
2
3
4
5
// Fetch All Records
DB::MySQL()->table('myTable')->select()->fetchAll();
// Still Fetches All Records
DB::MySQL()->table('myTable')->select()->limit(10)->fetchAll();

Note the fetchAll() method will return the results as an array of Data Objects. This differs from fetch(1) and fetchOne() which return the result as a Data Object.

Because the result is a an array of data objects, you can take advantage of Magic Data Manipulation and saving.

1
2
3
4
// Fetch and then Update Record
$r = DB::MySQL()->table('myTable')->select()->fetchAll();
$r[0]->name = 'new name';
$r[0]->save();

For more see Data Manipulation.