Refactored from mysql to PDO

Refactored code to use PDO API as well as separating concerns as best
as possible