Dial Plan question

I want to have a caller enter an employee number and validate that number to make sure it is an active employee from a database.

Example
caller calls in and enters 1234
I then would need to do some database validation and return whether or not I could find that 1234 in my employees table in my database.
If I found it I would do something
If I didn’t find it I would do something else.

And the question is ???

How do I do this?

  1. Using AGI
  2. Using Dialplan functions