Database class is not correctly connecting to my database.

Posted by blerh on Stack Overflow See other posts from Stack Overflow or by blerh
Published on 2010-05-01T18:43:04Z Indexed on 2010/05/01 18:47 UTC
Read the original article Hit count: 192

Filed under:
|
|
|
|

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.

© Stack Overflow or respective owner

Related posts about php

Related posts about class