views:

19

answers:

1

I'm just venturing into the world of OOP so forgive me if this is a n00bish question.

This is what I have on index.php:

$dbObj = new Database();
$rsObj = new RS($dbObj);

This is the Database class:

class Database
{
    private $dbHost;
    private $dbUser;
    private $dbPasswd;
    private $dbName;
    private $sqlCount;

    function __construct()
    {
        $this->dbHost   = 'localhost';
        $this->dbUser   = 'root';
        $this->dbPasswd = '';
        $this->dbName   = 'whatever';
        $this->sqlCount = 0;
    }

    function connect()
    {
        $this->link = mysql_connect($this->db_host, $this->db_user, $this->db_passwd);
        if(!$this->link)
                $this->error(mysql_error());

        $this->selection = mysql_select_db($this->db_name, $this->link);
        if(!$this->selection)
                $this->error(mysql_error());
    }
}

I've shortened it to just the connect() method to simplify things.

This is the RS class:

class RS
{
    private $username;
    private $password;

    function __construct($dbObj)
    {
        // We need to get an account from the db
        $dbObj->connect();

    }
}

As you can probably see, I need to access and use the database class in my RS class. But I get this error when I load the page:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\includes\database.class.php on line 22

The thing is I have NO idea where it got the idea that it needs to use ODBC as a user... I've read up on doing this stuff and from what I can gather I am doing it correctly.

Could anyone lend me a hand?

Thank you.

+2  A: 

The property names in connect() do not match the property names of the class.

Change:

$this->link = mysql_connect($this->db_host, $this->db_user, $this->db_passwd);

To:

$this->link = mysql_connect($this->dbHost, $this->dbUser, $this->dbPasswd);

And change:

$this->selection = mysql_select_db($this->db_name, $this->link);

To:

$this->selection = mysql_select_db($this->dbName, $this->link);
webbiedave