Using this:
$db = mysqli_connect
(
$db_host,
$db_user,
$db_pwd
) or die ("FATAL ! : The server ".$db_host." is not responding to ".$db_user."!");
how to get the $db value into this class (from include “class.php”) – without errors 😉
class User
{
public $db;
public $id;
public function getUser()
{
if($this->id)
{
$sql = "
SELECT
users.*
FROM
users
WHERE
users.u_id='".$this->id."'
";
$res = mysqli_query($db, $sql) or die(mysqli_error($db));
$user_row = mysqli_fetch_object($db, $res);
return $user_row;
}
else
{
return false;
}
}
} // end class User
All I get is – well, nothing. Exept my main page loads empty… If I stop using the class, all is well (exept no data for the user is shown ;-))
when you instantiate the class (User), if you have already assigned the variable ($db)… you can do
yes AND inside your class when you are referencing properties of the class from its methods, use the
$thisnotation… i.e. change$dbto$this->dbthat should work. you mentioned something about suppressing errors, that is a different issue. I am unsure what your goal is, but normal exception handling prior to the class’s instantiation would be adequate.