SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: getting variables into a class?
-
Apr 22, 2001, 09:52 #1
- Join Date
- Feb 2000
- Location
- England
- Posts
- 568
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I am using the db_mysql class from phplib but i want the servername, password etc variables to be in a different file that has already been included (or could be included from inside db_mysql.
How do i do this? using global did not work
-
Apr 22, 2001, 11:13 #2
- Join Date
- Apr 2000
- Posts
- 1,483
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Try putting this in the class:
PHP Code:var $username = $username;
var $password = $password;
Or you could declare the variables with var $variable as blank, then fill them in when you initiate the class in a script like this:
PHP Code:$class->username = $username;
$class->password = $password;
-
Apr 23, 2001, 05:54 #3
- Join Date
- Feb 2000
- Location
- England
- Posts
- 568
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
tried both of these, am complety stuck.
This is for example my top of the class:
PHP Code:class DB_Sql {
/* public: connection parameters */
var $host = "localhost";
var $database = "";
var $user = "root";
var $password = "";
PHP Code:$db = new DB_Sql;
$dbname="deskpro";
$db->user=$user;
$db->password=$password;
$db->host=$host;
$db->dbname=$dbame;
if i run the 2nd file, i always get the error
Code:Database error: cannot use database MySQL Error: 1046 (No Database Selected) Session halted.
doing var $username = $username; gave a syntax errror. The 2nd way is the way vb does it but i can't get it to work! any idea what i am doing wrong?
-
Apr 23, 2001, 06:00 #4
- Join Date
- Feb 2000
- Location
- England
- Posts
- 568
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
problem solved, don't worry
Bookmarks