DB::DBAL

The World's Most Powerful Light-Weight DBAL

FindOneBy…

findOneBy…( string $arg1 [, string $arg2, ...] )

The findOneBy…() magic method allows you to incorporate a where statement into the method name. To do this, simply start the method off as findOneBy followed by the column name (first letter uppercase). To add additional parameters, append AndBy or OrBy and the next column name. For the arguments, simply place the column values you would like to filter by, in order as setup in the method.

1
2
3
4
5
6
7
8
// Find One by Name WHERE Name = Joe
DB::MySQL()->table('myTable')->findOneByName('Joe');
// Find One by Name WHERE Name = Joe OR Bob
DB::MySQL()->table('myTable')->findOneByNameOrByName('Joe', 'Bob');
// Find One by Name And Age
DB::MySQL()->table('myTable')->findOneByNameAndByAge('Joe', '99');

Because the magic findOneBy…() method utilizes the fetchOne() method, other limits will not be respected, and only one record will be returned.

1
2
// Returns Only One Record
DB::MySQL()->table('myTable')->limit(10)->findOneByName('Joe');