I have set constants for database in connect.php.
connect.php
define('DB_HOST','localhost');
define('DB_NAME','dbname');
define('DB_USER','dbuser');
define('DB_PASSWORD','dbpass');
Here is the Database Class
require("connect.php");
class Database {
private $connect;
function opendb() {
$this->connect = new PDO(DB_NAME, DB_USER, DB_PASSWORD);
}
function closedb() {
$this->connect = null; //close connection
}
}
I get this error when i load the page that accesses the database class.
Fatal error: Uncaught exception 'PDOException' with message 'invalid data source name'
what did i do wrong?
You need to use this –