rewrote to use PDO

Refactored PHP code to use PDO.