This is a discussion on Problem With Constructor Function within the PHP Language forums, part of the PHP Programming Forums category; Hello, I have a nice, simple mySQL abstraction layer I have worked out in PHP. Recently I realized on a ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hello,
I have a nice, simple mySQL abstraction layer I have worked out in PHP. Recently I realized on a project that I wanted one of my objects to automatically clean-up its table on creation. I had been instantiating a News object in a page and then calling $newsObj->cleanUp(); So I changed the name of cleanUp() to News(). Seems simple enough right? Now it should clean up on instantiation... class News extends DBI { var $table = 'news'; function cleanUp() { $data = array( "endDate != '0000-00-00'", "endDate < NOW()" ); $this->delete($data); } } However, the constructor function did not have access to the $dbh inherited from the parent and threw the appropriate errors: Warning: mysql_query(): Access denied for user: 'talking@localhost' (Using password: NO) in /yata/yata/yata/classDBI.php on line 211 So my question to you, without much code to go on, is whether anyone knows why this would be? When I dumped $this it held what I would expect and was the Object type it should be. Thanks for any advice!! jg |
|
|||
|
Following on from jerrygarciuh's message. . .
>However, the constructor function did not have access to the $dbh inherited >from the parent and threw the appropriate errors: > Somewhere in the manual it says you need to explicitly call parent constructors. eg parent::ClassFoo() as 1st line in your constructor function. -- PETER FOX Not the same since the deckchair business folded peterfox@eminent.demon.co.uk.not.this.bit.no.html 2 Tees Close, Witham, Essex. Gravity beer in Essex <http://www.eminent.demon.co.uk> |
|
|||
|
Thanks Peter!!
jg "Peter Fox" <peterfox@eminent.demon.co.uk.not.this.bit.no.html > wrote in message news:ox$qpJAbNFGCFw1w@eminent.demon.co.uk... > Following on from jerrygarciuh's message. . . >>However, the constructor function did not have access to the $dbh >>inherited >>from the parent and threw the appropriate errors: >> > Somewhere in the manual it says you need to explicitly call parent > constructors. eg parent::ClassFoo() as 1st line in your constructor > function. > > -- > PETER FOX Not the same since the deckchair business folded > peterfox@eminent.demon.co.uk.not.this.bit.no.html > 2 Tees Close, Witham, Essex. > Gravity beer in Essex <http://www.eminent.demon.co.uk> |