Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Basic inheritance class issue!



2:11 am on May 9, 2010 (gmt 0)

5+ Year Member


I am new to PHP and struggling withe class inheritance.

Page name: DbConnectionClass.php

class DbConnectionClass{
protected $con;

protected function dbcon(){
$db = "abc";
$db_host = "localhost";
$db_user = "xyz";
$db_password = "******";
$this->dbCon =mysql_connect($db_host,$db_user,$db_password);

Page name: LoginClass.php

include ("DbConnectionClass.php");
class LoginClass extends DbConnectionClass{

function loginuser($username,$password){


There seems to be some kind of problem with mysql_close statement and in general am I being wrong some where?

Thank you


8:16 pm on May 9, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

Hi there impact,

Just doing this sort of thing myself! The thing I notice first is this:-


Shouldn't it be:-


You have declared the function as:-

protected function dbcon

And you have it there all lower case, try altering the other calls to the same thing ;) as the other instance has it with the 'c' in upper case 'C'.

I'm not too sure on the use of $this in this instance though as you are extending the class, it may well be right, I haven't got that far yet!

Pop the error checking on (error_reporting(E_ALL);) and I'm sure you will see some kind of notice being flagged up as you stand now

Hope this helps,



1:13 am on May 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

I would keep the db connection close statement encapsulated in the parent class. You have a function to establish the connection there already. Closing the connection should be there as well. This would also allow you to change the underlying db calls without affecting other classes. (And you may want to switch to using PDO...give it a look.)

Featured Threads

Hot Threads This Week

Hot Threads This Month