PHP mySQL connection problems

Pabloo

New Member
Ok, I am completely baffled.I am setting up an OO site. I have a class that defines all my database params, as follows:\[code\]$db->host= "localhost";$db->name= "mydatabase";$db->user= "user";$db->pw = "password";\[/code\]The class is being instantiated correctly and the values show up in pages that appear after this class has been loaded.BUT, when I try to connect to this database from a different class, it does not connect. Here's how I am connecting:\[code\]$dbconn = mysql_connect($db->host, $db->user, $db->pw);mysql_select_db($db->name, $dbconn);\[/code\]Everything works fine if I take out the user, pw and name variables and hard code in the correct values, but if any of them is referenced using the db construct, no connection happens. Again, the db construct appears just fine on other pages and I am seeing the variable values being presented correctly. The $db->host variable, however, always works.Here's is how I am constructing the db class:\[code\]class database { var $host; var $name; var $user; var $pw; function __construct($host = "localhost", $name = "mydatabase", $user = "user", $pw = "password"){ $this->host = $host; $this->name = $name; $this->user = $user; $this->pw = $pw; }}\[/code\]and then I of course do \[code\] $db = new database();\[/code\]Thanks in advance for any help!
 
Back
Top