PHP and Mysqli_connect issue
I created this class but now i have an issue passing the mysqi_connect into a global variable for other usage
class database{
protected $_link;
protected $_result, $_numRows;
public function __construct()
{
$this->_link = $this->connectDB();
}
private function connectDB()
{
$this->_link = mysqli_connect($this->server,$this->username,$this->password,$this->dbname);
mysqli_select_db($this->_link, $this->dbname);
var_dump($this->_link);
echo "<br>Connection was create;";
if (mysqli_connect_errno()) {
echo '<p>Cannot connect to DB: ' . mysqli_connect_error() . '</p>';
end;
}
}
//verify a login session
private function checkLogin($usr, $pass)
{
[extract]
$str = "Select * from user where username='$usr' and password='$pass' ";
$this->_result = mysqli_query(mysqli_connect($this->_link, $str); //$this_link is returning NULL....... Y?????????
$this->_numRows = mysqli_num_rows($this->_result);
if ($this->_numRows > 0)
{
echo $this->_numRows;
return true;
}
else
{
return false;
}
}
}
i get a the following warning:-
"Warning: mysqli_query() expects parameter 1 to be mysqli, null given in"
i call the instance :-
$mysql = new database;
$mysql->checkLogin($_POST['usr'], $_POST['pass'])
Why fight Information Technology when you can outsource IT