You are using PDO in your later code which is good. You next need to create a PDO connection. The docs give an example which was copied below. Obviously, you want to rename $dbh to $db.
Note that if you simple searched "php pdo", the first result would be http://php.net/manual/en/book.pdo.php which doesn't give any examples. Instead of randomly going through each link (which isn't necessarily a waste of time), always check the __construct link first.
PS. Get rid of all your constant definitions for your database connection values. At first you might think it is a good idea, but having too many constants gets complicated fast. I like to locate a file called config.ini in a secure location (i.e. not in your public root directory!) and use parse_ini_file() to convert it into an array.
<?php
/* Connect to a MySQL database using driver invocation */
$dsn = 'mysql:dbname=testdb;host=127.0.0.1';
$user = 'dbuser';
$password = 'dbpass';
try {
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
?>