473,382 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Defining vars outside the class

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
3 1275
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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Lüpher Cypher | last post by:
Ok, here's what I'm trying to do. I have a class. Inside the class I have a method that reads a text file. In the text file I have a class name and a file name where that class is defined. Now, I...
7
by: Harry Pehkonen | last post by:
I have been defining new class methods when I'm trying to simplify some code. But I'm thinking I should just define functions within that method because they aren't useful from the outside anyway....
0
by: Thys Meintjes | last post by:
Hi All, I've inherited a c library and is the process of wrapping it using Pyrex. The library code is a state machine and remembers previous values in order to determine new values on, for...
10
by: Joe Laughlin | last post by:
I'm sure there's a fairly easy answer for this... but how can I define a new type with range checking? Example: I want to define a new type that's like a double, except that you can only give...
1
by: Michael Stembera | last post by:
I have a case of a very simple template class w/ a template method. If I define a specialization of the method outside the body of the template class it does not compile. Here is a tiny example...
8
by: jody.florian | last post by:
Hi, I'm trying to use preg_replace_callback within a method. The preg_replace_callback() & mycallback() pair will only be used by this method, and this method will probably only be called once...
5
by: chrisstankevitz | last post by:
Why does this code only compile if GLOBAL_IN_STRUCT is defined? It creates a templated class C<T> and defines a global operator* that takes a C<T> on the LHS and a T on the RHS. In the...
9
by: Nick Maclaren | last post by:
I am defining a class, and I need to refer to that class when setting up its static data - don't ask - like this: Class weeble : wumpus = brinjal(weeble) Does anyone know how I can achieve...
7
true911m
by: true911m | last post by:
I'm getting ready to launch another long-winded project inquiry for feedback from you guys, cause I'm still working on the finer points of class implementation in my stubborn head. While I was...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.