homepage Welcome to WebmasterWorld Guest from 54.166.62.226
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Basic inheritance class issue!
impact

5+ Year Member



 
Msg#: 4129596 posted 2:11 am on May 9, 2010 (gmt 0)

Hello,

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);
mysql_select_db($db);
}
}


Page name: LoginClass.php

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

function loginuser($username,$password){
$this->dbcon();
-
-
-
mysql_close($this->con);
}

}

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

Thank you

 

Matthew1980

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4129596 posted 8:16 pm on May 9, 2010 (gmt 0)

Hi there impact,

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

mysql_close($this->con);

Shouldn't it be:-

mysql_close($this->dbcon);

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,

Cheers,
MRb

FourDegreez

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4129596 posted 1:13 am on May 10, 2010 (gmt 0)

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.)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved