Help - Search - Member List - Calendar
Full Version: Problem making a class extending another
WorkTheWeb Forums > Webmaster Resources > PHP Help
Support our Sponsors!
Peter
Hi All

I have only just started using inheritance etc and am lost a bit.

I am using the DB pear package but I am writing a class that will hopefully
use the pear package.

My class uses extends DB after the name of it.

When I call the connect function that is within the DB class it works with
no problem but when I try and use the query function I get the function does
not exist error message. Having looked in the DB pear package files I have
found that the connect function is within the main DB class in DB.php but
the query function is in the common.php file.

How do I go about it so that my class can use every function within the DB
class.

Stefan Rybacki
Peter wrote:
QUOTE
Hi All

I have only just started using inheritance etc and am lost a bit.

I am using the DB pear package but I am writing a class that will hopefully
use the pear package.

My class uses extends DB after the name of it.

When I call the connect function that is within the DB class it works with
no problem but when I try and use the query function I get the function does
not exist error message. Having looked in the DB pear package files I have
found that the connect function is within the main DB class in DB.php but
the query function is in the common.php file.

How do I go about it so that my class can use every function within the DB
class.


To get further help you should present some code you are using. And I

don't mean the code of the pear class. I mean just the code you use to
use the pear class.

Regards
Stefan

Peter
QUOTE
To get further help you should present some code you are using. And I
don't mean the code of the pear class. I mean just the code you use to use
the pear class.

Regards
Stefan

Hi

I have taken out any unnecessary code.

class my_class extends DB
{
function check_user($user_name)
{
global $_SERVER;
$sql = 'select * from users where username =
''.htmlspecialchars($user_name).'' AND browser =
md5(''.mysql_real_escape_string($_SERVER['HTTP_USER_AGENT']).'') AND
session_id = md5(''.htmlspecialchars(session_id()).'')';
$confirm_user = parent::query($sql);
if ($confirm_user->numRows()==1)
{
$_SESSION['logged_in'] = true;
}
}
}

as you can see I have tried parent::query($sql); I have also tried
DB::query($sql); but that does not work either, in both cases it displays an
error saying the following:-

Fatal error: Call to undefined function: db() in
/home/petermcd/public_html/the.php on line 25

Stefan Rybacki
Peter wrote:
QUOTE
To get further help you should present some code you are using. And I
don't mean the code of the pear class. I mean just the code you use to use
the pear class.

Regards
Stefan


Hi

I have taken out any unnecessary code.

class my_class extends DB
{
function check_user($user_name)
{
global $_SERVER;
$sql = 'select * from users where username =
''.htmlspecialchars($user_name).'' AND browser =
md5(''.mysql_real_escape_string($_SERVER['HTTP_USER_AGENT']).'') AND
session_id = md5(''.htmlspecialchars(session_id()).'')';
$confirm_user = parent::query($sql);
if ($confirm_user->numRows()==1)
{
$_SESSION['logged_in'] = true;
}
}
}

as you can see I have tried parent::query($sql); I have also tried
DB::query($sql); but that does not work either, in both cases it displays an
error saying the following:-

Fatal error: Call to undefined function: db() in
/home/petermcd/public_html/the.php on line 25


I'm not very familar with the pear packages. As I can see is query a

method of a class called DB. And since you derived your class of DB you
should simply call query() without anything before (e.g. parent or DB).

Another thing that makes me stuck is that the error message tells you
something about a function called db() and I don't see such a function
in your code?!

Regards
Stefan

Peter
QUOTE
I'm not very familar with the pear packages. As I can see is query a
method of a class called DB. And since you derived your class of DB you
should simply call query() without anything before (e.g. parent or DB).

Another thing that makes me stuck is that the error message tells you
something about a function called db() and I don't see such a function in
your code?!

Regards
Stefan

Sorry the error message should have been

Fatal error: Call to undefined function: query() in
/home/petermcd/public_html/the.php on line 25

I have tried just calling it by the function name and this has the same
result, I am presuming it is the way that it calls this function.

Stefan Rybacki
Peter wrote:
QUOTE
I'm not very familar with the pear packages. As I can see is query a
method of a class called DB. And since you derived your class of DB you
should simply call query() without anything before (e.g. parent or DB).

Another thing that makes me stuck is that the error message tells you
something about a function called db() and I don't see such a function in
your code?!

Regards
Stefan


Sorry the error message should have been

Fatal error: Call to undefined function: query() in
/home/petermcd/public_html/the.php on line 25

I have tried just calling it by the function name and this has the same
result, I am presuming it is the way that it calls this function.


Ok after reading I found out that the query function is not a member of

the DB class.

Its member of the connection class. Use like this:

$conn = DB::connect ($dsn, $options);
$result = $conn->query ($query_str);


More information at:
http://www.kitebird.com/articles/peardb.html

May you ask aunt google from time to time ;)

Regards
Stefan

Peter
QUOTE
Ok after reading I found out that the query function is not a member of
the DB class.

Its member of the connection class. Use like this:

$conn = DB::connect ($dsn, $options);
$result = $conn->query ($query_str);


More information at:
http://www.kitebird.com/articles/peardb.html

May you ask aunt google from time to time ;)

Regards
Stefan

Thanks Stefan much apreciated, I did have a search on google but couldn't
find anything, obviously looking for the wrong thing :>


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2006 Invision Power Services, Inc.