deciperhing oop
| From: | Larry Brown | Date: | Mon, 03 Mar 2003 22:52:23 +0000 |
| Subject: | deciperhing oop | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-137981@lists.php.net to get a copy of this message | ||
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