php mysql tutorial

Php Mysql Select Birthdays Between the Last and Next 7 Days



In this example I show how to get birthday dates from a mysql database. The time interval is -7 <-> +7 days.


Let’s create the test environment first!

You need to have a working web server with php and mysql.

  • Mysql username: testing
  • Mysql database: testing
  • Mysql password: test123


Create mysql database connection

You need to create a php file for the mysql database connection.

Filename: db.php

This file builds up the connection to the mysql database. The $setutf is a small trick to handle UTF8 characters (probably you don’t need this).


Create the database table with persons

You create the database table with the persons and birthday dates.

filename: build.php


Check the results

You can check the birthdays with the index.php.

filename: index.php

This code is responsible for the time interval:


Drop the table

Drop the table and restart the test if you want.

filename: drop.php


How to play with the files?

So there are 4 files:

  • db.php
  • build.php
  • index.php
  • drop.php

You can download the files in a zip file from here.

Please do not forget you need to have a running php web server and a mysql server.

You need to use the files in the following order:



It’s your turn

Have you noticed that Michael is never on the list? Check the build.php file and you’ll find the reason!



Posted by:

Balazs Hende
I am a blogger and the founder of this site. I have started on October 1, 2013. Have a pleasant stay here!

Related articles


Back to Top