FetchOne
fetchOne( void )
The fetchOne() method is used to retrieve a single record back from a query. This is the equivalent of using the limit() method and the fetch() method, or using fetch(1).
1 2 3 4 5 |
// Fetch One Record
DB::MySQL()->table('myTable')->select()->fetchOne(); // Still Fetches Only One Record
DB::MySQL()->table('myTable')->select()->limit(10)->fetchOne(); |
Note the fetchOne() method will return the result as a Data Object. This differs from fetch(2 or more) and fetchAll() which return an array of Data Objects.
Because the result is a data object, 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()->fetchOne(); $r->name = 'new name'; $r->save(); |
For more see Data Manipulation.