PDO = new PDO( "mysql:host=".DB_HOST.";port=".DB_PORT.";dbname=".DB_NAME, DB_USER, DB_PASS ); // Set the connection to use utf8 encoding $this->PDO->exec("SET NAMES utf8"); } catch(PDOException $ex) { // Display error message if connection fails echo "

Problem with database!

"; die("
" . $ex . "
"); } } /** * Perform a SELECT query on the database. * * @param string $query The SQL query to execute. * @param array $bindings An associative array of parameters and their values. * @return array|false Returns an array of rows as associative arrays or false if no results are found. */ public function select($query, $bindings = array()) { // Prepare and execute the SQL query $STH = $this->PDO->prepare($query); $STH->execute($bindings); // Fetch the results as associative arrays $result = $STH->fetchAll(PDO::FETCH_ASSOC); if ($result === false) { $result = array(); // Set $result to an empty array if no results found } return $result; } /** * Perform a non-query SQL statement on the database. * * @param string $query The SQL query to execute. * @param array $bindings An associative array of parameters and their values. * @return bool Returns true on success or false on failure. */ public function query($query, $bindings = array()) { // Prepare and execute the SQL query $STH = $this->PDO->prepare($query); return $STH->execute($bindings); } }