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 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. 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 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
Archived
This topic is now archived and is closed to further replies.