Thank you everyone for helping.  I didn't know you have to put $this-> in
front of all variables in the class.  You learn something new every day ( I
thought you only needed to use that once to make the variable available
everywhere in the class up till now).

Larry S. Brown
Dimension Networks, Inc.
(727) 723-8388

-----Original Message-----
From: Jim Lucas [mailto:[EMAIL PROTECTED]
Sent: Monday, March 03, 2003 6:50 PM
To: Larry Brown; PHP List
Subject: Re: [PHP] deciperhing oop

the second argument in the mysql_select_db call in not in scope.

you should be using $this->db instead of $db

Jim
----- Original Message -----
From: "Larry Brown" <[EMAIL PROTECTED]>
To: "PHP List" <[EMAIL PROTECTED]>
Sent: Monday, March 03, 2003 2:52 PM
Subject: [PHP] deciperhing oop


> Can someone who is used to using php oop help me figure out why this
fails?
> I know there are probably a thousand classes already designed to do this
and
> probably 100 times more efficient, but this is how I learn.  From what
I've
> read this should work but there is obviously something I'm missing.
>
> Quick problem description:
> Trying to set up class to connect to mysql db.  Already used a procedural
> test successfully connecting to db.  Error is displayed as...
>
> Warning: mysql_select_db(): supplied argument is not a valid MySQL - Link
> resource in /var/www/html/oop.php on line 67
> Database Selection to main failed.
>
> Code:
>
> Class dbConnect
> {
> var $machine;
> var $port;
> var $user;
> var $password;
> var $query;
> var $result;
> var $dbase;
> var $db;
> var $sel;
>
> function dbConnect($machine,$port,$user,$password)
> {
> $this->machine = $machine;
> $this->port = $port;
> $this->user = $user;
> $this->password = $password;
>
> $db = mysql_pconnect ("$machine","$user","$password")
> if (!$db)
> {
> die ("Initial connection to DB failed.")
> }
> $this->db = $db;
> }
> function setDbase($dbase)
> {
> $this->dbase = $dbase;
>
> $sel = mysql_select_db("$dbase",$db);
> if(!$db)
> {
> die ("Database Selection to $dbase failed.");
> }
> }
> }
>
> $dbn = new dbConnect("localhost","3306","bob","hjhyt4kl5");
>
> $dbn->setDbase("main");
>
>
>
>
>
>
> So why can't I use $db?  Isn't the statement $this->db=$db making it
> available to the setDbase function?
>
> Larry S. Brown
> Dimension Networks, Inc.
> (727) 723-8388
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to