AbydosGater Posted April 1, 2007 Share Posted April 1, 2007 Hey im sorry, Im sure there is a simple answer to this but im a n00b to oop. And ive been working on a simple page creation script for about the last 20 minutes haha. Right to the point. Im using the code... <?php class CreatePage{ //Initialize The Class //Variable Setup var $title; var $navlinks; var $rightnav; var $footer; var $dbuser; var $dbpass; var $dbname; //End Variable Setup //Function Creation function __construct($title){ //Constructor $page->title = $title; $page->dbuser = "stargate_admin"; $page->dbpass = "iolar84"; $page->dbname = "stargate_system"; } function dbconnect(){ mysql_connect("localhost", $page->dbuser, $page->dbpass); mysql_select_db($page->dbname); } } //Closing The Class $thePage = new CreatePage("Andys Page"); $thePage->dbconnect(); ?> I know its not much. But how do i get the variables to go into the mysql_connect cause im getting errors about there being noone as a username so its no printing the variable for user and pass there. Could someone please help? Andy Link to comment https://forums.phpfreaks.com/topic/45205-mysql-error-with-a-simple-class-easy-answer-but-im-an-oop-n00b/ Share on other sites More sharing options...
emehrkay Posted April 1, 2007 Share Posted April 1, 2007 replace $page with $this $this means it is referencing itself Link to comment https://forums.phpfreaks.com/topic/45205-mysql-error-with-a-simple-class-easy-answer-but-im-an-oop-n00b/#findComment-219467 Share on other sites More sharing options...
AbydosGater Posted April 1, 2007 Author Share Posted April 1, 2007 Ahhhhh wasnt sure what the $this in my php book was for so i just used $pages. Thanks Andy Link to comment https://forums.phpfreaks.com/topic/45205-mysql-error-with-a-simple-class-easy-answer-but-im-an-oop-n00b/#findComment-219468 Share on other sites More sharing options...
trq Posted April 1, 2007 Share Posted April 1, 2007 Replace all instances of $page with $this. I'm not sure where you got the idea for $page from, but $this is a special variable used within classes to refer to the instantiated object itself. Link to comment https://forums.phpfreaks.com/topic/45205-mysql-error-with-a-simple-class-easy-answer-but-im-an-oop-n00b/#findComment-219469 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.