put a echo in the constructor to see if it is being called
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
i did... and it is..this is why i dont understand what is happening... i am unable to pass the connection to variable $_link... if u look there is on in the actural function... that say "connection created"
Why fight Information Technology when you can outsource IT
i got it work...
in the constructor i replaced with this:- $_link = $this->connectDB();
Why fight Information Technology when you can outsource IT
Hello,
Anyone needing help Working With JSON, JQuery, PHP and Mysql can checkout this tutorial
//ESTABLISH DATABASE CONNECTION
define("DB_SERVER", "localhost");
define("DB_USER", "root");
define("DB_PASS", "");
define("DB_NAME", "myDB");
//Connect to mysql server
$link=@mysqli_connect(DB_SERVER,DB_USER,DB_PASS,DB _NAME);
if(!$link) {
print("Failed to establish connection to mysql server!");
exit();
}
if(isset($_POST['keyword'])){
$keyword = trim($_POST['keyword']);
$keyword = mysqli_real_escape_string($link, $keyword);
$query = "select meter_name,meter_location from meters where meter_name like '$keyword%'"; //MUST BEGIN WITH $KEYWORD
//echo $query;
$result = mysqli_query($link,$query);
if($result){
if(mysqli_affected_rows($link)!=0){
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){
echo '<span><a class="meterRow">'.$row['meter_name'].'</a><span>'.$row['meter_location'].'</span></span>';
}
}else {
echo 'No Results for :"'.$_POST['keyword'].'"';
}
}
}else {
echo 'Parameter Missing';
}