I am building a class that will handle all of my database record modifications (class SCFE_DB_mod)
Here is the current class:
class SCFE_DB_mod{
public function __construct(){ //initiate database connection
require __DIR__ . "/../system/system.db_conn.php";
}
public function __destruct(){ //terminate database connection
require __DIR__ . "/../system/system.db_close.php";
}
}
In my __construct() I have a require statement that loads the file with my database connection
include_once __DIR__ . '/../settings/settings.system.database.php';
// PDO Database Connection String // // <== DONT CHANGE THIS VALUE
switch(DB_SERVER_TYPE){
case 1: //mySQL
$db_connStr = 'mysql:host=' . DB_SERVER . ';dbname=' . DB_NAME;
break;
case 2: //MSSQL / MS Azure
$db_connStr = 'sqlsrv:host=' . DB_SERVER . ';dbname=' . DB_NAME;
break;
}
$pdoOptions = array(
//DONT CHANGE THESE VALUES
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_EMULATE_PREPARES => FALSE);
// DONT CHANGE THE FOLLOWING
try{
$db_conn = new PDO($db_connStr, DB_USER, DB_PASS, $pdoOptions);
}catch (PDOException $err){
print 'Error: ' . $err->getMessage() . '<br/>';
die();
}
would I be able to call the $db_conn variable from other methods or is there something else I would need to do?
Guidance is appreciated.