CaptainChainsaw Posted July 15, 2008 Share Posted July 15, 2008 Hi all, I can't seem to connect to the DB, I believe there is a problem somewhere with my dbconnection class as the line echo "here"; doesn't output anything. <?php class dbconnection{ private $_dbhost=''; private $_dbusername=''; private $_dbpassword=''; private $_dbname=''; private $_dbconn=''; public function __construct($dbhost, $dbusername, $dbpassword, $dbname) { $this->$_dbhost=$dbhost; $this->$_dbusername=$dbusername; $this->$_dbpassword=$dbpassword; $this->$_dbname=$dbname; echo "here"; } public function connect(){ $this->$_dbconn = mysql_connect($this->$_dbhost, $this->$_dbusername, $this->$_dbpassword) or die ('Error connecting to mysql'); return $this->$_dbconn; } public function select(){ mysql_select_db($this->$_dbname, $this->$_dbconn); } } ?> Here's the code I used to instantiate the class. <? $db=new dbconnection($conf->getConfItem('dbhost'), $conf->getConfItem('dbusername'), $conf->getConfItem('dbpassword'), $conf->getConfItem('dbname')); $db->connect; $db->select; ?> the $conf items are being correctly passed in so it can't be that. Any ideas? Thanks again, CC Quote Link to comment https://forums.phpfreaks.com/topic/114910-solved-db-connection-class-prob-another-easy-one/ Share on other sites More sharing options...
next Posted July 15, 2008 Share Posted July 15, 2008 You have an error in your syntax. In constructor for instance: $this->$_dbhost=$dbhost; should be: $this->_dbhost=$dbhost; properties don't have a '$' prefix. Quote Link to comment https://forums.phpfreaks.com/topic/114910-solved-db-connection-class-prob-another-easy-one/#findComment-590972 Share on other sites More sharing options...
CaptainChainsaw Posted July 15, 2008 Author Share Posted July 15, 2008 Hi there, thanks for that, I've had to change a number of classes *sigh*, much appreciated! CC Quote Link to comment https://forums.phpfreaks.com/topic/114910-solved-db-connection-class-prob-another-easy-one/#findComment-591046 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.