ensinger
10-16-2006, 01:36 AM
I am creating a class to work with a knowledge base database. the class only works if I hardcode the database or pass it into each function that works with the database. Below is a scaled down version of the class, any explanation as to why it fails when selecting the database would be appreciated.
class kb
{
function kb($server = "localhost", $database = "KnowledgeBase")
{
$this->$server = $server;
$this->$database = $database;
}
function ShowOptions()
{
$link = mysql_connect($this->$server)
or die("Could not connect : " . mysql_error());
mysql_select_db($this->$database, $link) or die("Could not select database");
}
var $server;
var $database;
}
I'm using php 4 still, what gives? Should I update php on my development pc? Is this a bug or am I doing something wrong?
class kb
{
function kb($server = "localhost", $database = "KnowledgeBase")
{
$this->$server = $server;
$this->$database = $database;
}
function ShowOptions()
{
$link = mysql_connect($this->$server)
or die("Could not connect : " . mysql_error());
mysql_select_db($this->$database, $link) or die("Could not select database");
}
var $server;
var $database;
}
I'm using php 4 still, what gives? Should I update php on my development pc? Is this a bug or am I doing something wrong?