Object instance and session
| From: | Stefano Esposito | Date: | Tue, 24 Jul 2007 09:44:16 +0000 |
| Subject: | Object instance and session | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-259414@lists.php.net to get a copy of this message | ||
Hi all,
i've a self-defined class describing an user. In the login page i create an instance of the
user object and store it in $_SESSION['user']. When accessing $_SESSION['user']
from other pages (of course I do require('user.php'); and session_start();) i got this
errors:
Warning: mysqli::query() [function.mysqli-query]: Couldn't fetch mysqli in
/home/httpd/html/uss_tyco3/user.php on line 390
Warning: user::get_unita_row() [function.user-get-unita-row]: Couldn't fetch mysqli in
/home/httpd/html/uss_tyco3/user.php on line 391
Fatal error: Call to a member function fetch_assoc() on a non-object in
/home/httpd/html/uss_tyco3/user.php on line 396
The constructor is:
function __construct ($nick, $pwd)
{
$conn = new mysqli ("localhost", "****", "*************",
"tyco");
$this->conn = $conn;
$query = "SELECT * FROM
users WHERE nick='$nick'";
$res = $conn->query($query);
if (!$res->num_rows)
{
/* The nick isn't registered */
$this->log("Nick inesistente: $nick");
return 1;
}
$row = $res->fetch_assoc();
$res->free_result();
if ($row['password'] != $pwd)
{
/* Wrong password */
$this->log("Password errata, nick: $nick");
return 2;
}
$query = "INSERT INTO online (user) VALUES ('$nick') ON
";
$query .= "DUPLICATE KEY UPDATE time='".time()."'";
$conn->query ($query);
if ($conn->error)
{
/* Error in mysql query */
$this->log($conn->error);
return FALSE;
}
$this->nick = $nick;
$this->pwd = $pwd;
$this->admin = (bool)$row['admin'];
$this->master = (bool)$row['master'];
$this->log("Login: $nick");
}
The method i'm calling when getting those errors is:
function get_unita_row ()
{
$query = "SELECT * FROM unita WHERE
id='$this->unita'";
$res = $this->conn->query($query);
if ($this->conn->error)
{
$this->log($this->conn->error);
return FALSE;
}
$row = $res->fetch_assoc();
$res->free_result();
return $row;
}
Any hint?
Thanks,
Stefano
--
Email.it, the professional e-mail, gratis per te: http://www.email.it/f
Sponsor:
250 biglietti da visita Gratis + 42 modelli e Etichette per Indirizzo Gratis + Porta biglietti
Gratis -Offerta limitata!
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=6782&d=24-7