DEV Community

Benyamin Khalife
Benyamin Khalife

Posted on • Edited on

SQL And PHP: People whose birthday is today

How do we find a list of people whose birthday is today from a database and perform an operation on them?

To start, we add the Foxdb library:

composer require webrium\foxdb 
Enter fullscreen mode Exit fullscreen mode

In this way, write the default configuration for using the library and change it according to your project.

use Foxdb\DB; use Foxdb\Config; use Foxdb\DB; DB::addConnection('main', [ 'host'=>'localhost', 'port'=>'3306', 'database'=>'test', 'username'=>'root', 'password'=>'1234', 'charset'=>Config::UTF8, 'collation'=>Config::UTF8_GENERAL_CI, 'fetch'=>Config::FETCH_CLASS ]); 
Enter fullscreen mode Exit fullscreen mode

Now, using a simple query, we can get the list of people whose birthday is today.

$list = DB::table('users') ->month('birth_date', date('m')) ->day('birth_date', date('d')) ->get(); 
Enter fullscreen mode Exit fullscreen mode

See the GitHub repository and documentation at the link below.

FoxDB Documentation

Top comments (0)