This code gets an error.
Fatal error: Call to a member function prepare() on a non-object in C:\wamp\www\progapps\addReminder.php on line 12
Here is my code:
addReminder.php
<?php
include_once("includes/database.php");
try {
global $dbh;
$query = $dbh -> prepare("SELECT * FROM reminder_type;");
$query->setFetchMode(PDO::FETCH_ASSOC);
$query ->execute();
} catch(PDOException $ex) {
echo $ex->getMessage();
}
?>
This is the connection of the database.
database.php
<?php
include("constants.php");
class MySQLDB {
function MySQLDB(){
global $dbh;
try{
$dbh = new PDO('mysql:host='.DB_SERVER.';dbname='.DB_NAME.'',DB_USER,DB_PASS);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
}catch(PDOException $e){
echo $e->getMessage();
die();
}
}
}
Here are the constants
constants.php
<?php
$currency = '₱';
define("DB_SERVER", "localhost");
define("DB_USER", "root");
define("DB_PASS", "");
define("DB_NAME", "hrisdb");
?>
What is the possible cause? And how can I solve this problem? Thank you, guys!