Please Check My MySQLi Class
Posted: Fri Aug 27, 2010 6:42 pm
I have tried to create a basic class that will connect to mysql using mysqli.
The idea is that another class will you this code to connect to the database and then run some queries.
This is the class.
I haven't tested it yet, i just wanted some advise on how to improve it.
Many Thanks For Your time.
Chris
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