473,763 Members | 1,320 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_USERNAM E, &$db_PASSWOR D, &$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>dbUser name= $this->USERNAME<br> dbPassw= $this->PASSWORD<br>db Name= $this->DBNAME<br>") ;}
}

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

vars are empthy !!!!!!!!
May 26 '06 #1
3 1302
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>databa se
error= ".mysql_error() );
$connection = mysql_connect($ this->HOST, $this->USERNAME,
$this->PASSWORD) or die ("<br>".mysql_e rror());

$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******** ********@newsfe 2-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>databa se
error= ".mysql_error() );
$connection = mysql_connect($ this->HOST, $this->USERNAME,
$this->PASSWORD) or die ("<br>".mysql_e rror());

$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******** ********@newsfe 2-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>databa se
error= ".mysql_error() );
$connection = mysql_connect($ this->HOST, $this->USERNAME,
$this->PASSWORD) or die ("<br>".mysql_e rror());

$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 "$setdbconf ig"
May 26 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3060
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 need to instantiate an object of that class, the problem being that at the time I find out the class name and the file name, I'm inside a method of another class. Well, let me just type up a little example: class MainClass { $obj = null;
7
3051
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. Example: Before: class Mess(object): def complicated(self, count):
0
994
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 example, a decode() call. These "state-full" variables were all implemented using 'extern' in the c code. My wrapper works fine if I have only one instance of my new type myclass. However, when I create more than one instance of myclass it
10
1875
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 it values from 0.0 to 100.0. I'd also like it to act like a double as much as possible, except that an exception is thrown when it's set to an invalid number. Ideas?
1
6284
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 to illustrate. template<typename T> class C { public:
8
4480
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 in the object's lifetime (so there's no sense in making the callback function a method of the class...(is there??)) Instead, I wanted to use create_function() to create a make-shift callback function within the method. (seeing as you can't...
5
1768
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 example, T is double, but I call the global operator* with a float. Thanks for your help,
9
1240
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 this? Naturally, I don't need anything more than the address of the class in brinjal, as it won't be used until after the class has been created properly. Actually, it won't be used except to test for class equivalence, but I may
7
2028
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 playing around with an idea, I was reading about class vs. instance variables. I tried a few in multiple instances of a class, and I don't really get the big difference. Instance variables are definitely harder to get at -- it appears the class must...
0
9386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9998
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.