Jump to content

[SOLVED] db connection class (prob another easy one)


CaptainChainsaw

Recommended Posts

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 :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.