Re: Usage of BD.php inside a class
| From: | Luc Saint-Elie | Date: | Fri, 13 Apr 2001 20:11:02 +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-46@lists.php.net to get a copy of this message | ||
Dean
I tried $this-db because if I call my database connection with $db
require_once( 'DB.php' );
Class MyClass {
function MyFunctionInsideAClass(){
[....]
$db = DB::connect( "mysql://$dbuser:$dbpass@$dbhost/$dbname" );
$sql = "select id from login where username = '$username' and password = '$password'";
THIS IS LINE 140 $query = $db->query($sql);
$result =$db->numRows($query);
$db->disconnect();[....] I get : Fatal error: Call to undefined function: query() in backend.php on line 140 Luc At 14:51 13/04/01 -0500, Dean Hall wrote:
"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'";$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.THIS IS LINE 139 $query = $this->db->query($sql);