The idea is that another class will you this code to connect to the database and then run some queries.
Code: Select all
$dbConnection = new dbConnection("attributes");
$isConnected = $dbConnection->connectToDB();Code: Select all
class dbConnection
{
private $_hostName;
private $_userName;
private $_userPassowrd;
private $_dbName;
private $_dbConnection;
public function __construct($hostName, $userName, $userPassword, $dbName)
{
$this->_hostName = $hostName;
$this->_userName = $userName;
$this->_userPassword = $userPassword;
$this->_dbName = $dbName;
}
public function connectToDB()
{
$this->_dbConnection = new mysqli($this->_hostName, $this->_userName, $this->_userPassword, $this->_dbName);
return ($this->_dbConnection) ? true : false;
}
}Many Thanks For Your time.
Chris