| Basic inheritance class issue!
|
impact

msg:4129598 | 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

msg:4129830 | 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

msg:4129914 | 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.)
|
|
|