By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,292 Members | 1,642 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,292 IT Pros & Developers. It's quick & easy.

Defining vars outside the class

P: n/a
Using PHP version: 4.3.7
I try to define my db vars outside the class!
Why this will not work?
class mytest{

//***************** set db settings ***************************
var $HOST ;
var $USERNAME;
var $PASSWORD;
var $DBNAME;

function setdb( &$db_HOST, &$db_USERNAME, &$db_PASSWORD, &$db_DBNAME){

$this-> HOST =& $db_HOST;
$this-> USERNAME =& $db_USERNAME;
$this-> PASSWORD = & $db_PASSWORD;
$this-> DBNAME = & $db_DBNAME;

// OK this will print the vars
echo ("dbHost= $this->HOST<br>dbUsername= $this->USERNAME<br> dbPassw= $this->PASSWORD<br>dbName= $this->DBNAME<br>");}
}

//test example
........
$dbhost = "localhost"; // DB Host name
$dbusername = "username"; // DB User
$dbpass = ""; // DB User password
$dbname = "mydb"; // DB Name
$setdbconfig=new mytest();
$x= $setdbconfig->setdb(& $dbhost,& $dbusername,& $dbpass,& $dbname);
........
$SelectedDB = mysql_select_db( $this->DBNAME) or die ("<br>database error= ".mysql_error());
$connection = mysql_connect($this->HOST, $this->USERNAME, $this->PASSWORD) or die ("<br>".mysql_error());
.........

vars are empthy !!!!!!!!
May 26 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
freak said the following on 26/05/2006 18:54:
Using PHP version: *4.3.7*
I try to define my db vars outside the class!
Why this will not work?
class mytest{
...
}

//test example
...
$SelectedDB = mysql_select_db( $this->DBNAME) or die ("<br>database
error= ".mysql_error());
$connection = mysql_connect($this->HOST, $this->USERNAME,
$this->PASSWORD) or die ("<br>".mysql_error());

$this doesn't exist outside a class.
P.S. Please post in this newsgroup as plain-text only.
--
Oli
May 26 '06 #2

P: n/a

"Oli Filth" <ca***@olifilth.co.uk> schreef in bericht
news:ax****************@newsfe2-gui.ntli.net...
freak said the following on 26/05/2006 18:54:
Using PHP version: *4.3.7*
I try to define my db vars outside the class!
Why this will not work?
class mytest{
...
}

//test example
...
$SelectedDB = mysql_select_db( $this->DBNAME) or die ("<br>database
error= ".mysql_error());
$connection = mysql_connect($this->HOST, $this->USERNAME,
$this->PASSWORD) or die ("<br>".mysql_error());

$this doesn't exist outside a class.
P.S. Please post in this newsgroup as plain-text only.
--
Oli


OK so what is the solution ???
May 26 '06 #3

P: n/a
freak wrote:
"Oli Filth" <ca***@olifilth.co.uk> schreef in bericht
news:ax****************@newsfe2-gui.ntli.net...
freak said the following on 26/05/2006 18:54:
Using PHP version: *4.3.7*
I try to define my db vars outside the class!
Why this will not work?
class mytest{
...
}

//test example
...
$SelectedDB = mysql_select_db( $this->DBNAME) or die ("<br>database
error= ".mysql_error());
$connection = mysql_connect($this->HOST, $this->USERNAME,
$this->PASSWORD) or die ("<br>".mysql_error());

$this doesn't exist outside a class.
P.S. Please post in this newsgroup as plain-text only.
--
Oli


OK so what is the solution ???


use the object name "$setdbconfig"
May 26 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.