Re: Usage of BD.php inside a class
| From: | Dean Hall | Date: | Fri, 13 Apr 2001 19:51:54 +0000 |
| Subject: | Re: Usage of BD.php inside a class | ||
| References: | 1 2 3 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-45@lists.php.net to get a copy of this message | ||
"Luc Saint-Elie" <luc@saint-elie.com> wrote
> I discovered another problem
>
> The following is part of a class.. and php complains
> >Fatal error: Call to a member function on a non-object in backend.php on
> line 139
>
> //==================================
> function login ($username, $password) {
[...]
> $db =
B::connect( "mysql://$dbuser:$dbpass@$dbhost/$dbname" );
> $sql = "select id from login where username =
'$username' and password = '$password'";
> >> THIS IS LINE 139 $query = $this->db->query($sql);
> $result =$this->db->numRows($query);
> $this->db->disconnect();
> [.....]
> //==================================
> Where did I screw up ?
>
> Luc
Well, on line 137, you refer to the database object as '$db', and on line
139, you refer to it as '$this->db'. You probably just need to change it to
'$db', or you need to assign the DB::connect() return value to '$this->db'
instead of $db -- whichever suits your needs.
Dean.