I am making a minor CMS for specific use at my current job, and I want to do it right... hence OOP.
For this I want to make a database connection class that I can use in my other classes when I need to make database queries. However, for some reason, I keep being stopped at the same point, because I don't seem to be able to get the connection string into my classes.
Whatever changes I make, I end up with "undefined... " something every time.
File - databaseManagement.class.php:
class database {
private $user;
private $pass;
private $db;
private $serv;
private $type;
private $dsn;
private $sqlsrvString;
private $charset;
private $dbIni;
private $options;
public $connectionInfo;
public $dbConn;
public function __construct() {
$this->dbIni = parse_ini_file('settings/database.ini.php');
// ... assign values to individual variables based on values in the database.ini.php file.
$this->user = $this->dbIni['user'];
$this->pass = $this->dbIni['pass'];
$this->db = $this->dbIni['db'];
$this->serv = $this->dbIni['serv'];
$this->type = $this->dbIni['type'];
$this->charset = $this->dbIni['charset'];
$this->connectionInfo = array(
"Database"=>$this->db,
"UID"=>$this->user,
"PWD"=>$this->pass
);
}
public function dbConnect() {
$this->dbConn = sqlsrv_connect($this->serv, $this->connectionInfo);
}
File - smallInfo.class.php
class smallInfo {
function __construct() {
$initDB = new database();
$initDB->dbConnect();
var_dump($initDB);
}
function showDkProgress(){
echo "<hr />";
print_r($initDB->dbConn);
echo "<hr />";
}
Now the var_dump() in smallInfo constructor returns all the expected values, including those of $dbConn, however, I can't seem to access $dbConn in showDkProgress() for use in queries.