mysql_close(): supplied argument is not a valid MySQL-Link resource

Posted by Illes Peter on Stack Overflow See other posts from Stack Overflow or by Illes Peter
Published on 2010-04-26T13:45:12Z Indexed on 2010/04/26 13:53 UTC
Read the original article Hit count: 252

Filed under:
|

Here's what I'm trying to do: I've got a db.php file that does all the db manipulation.

It has 2 static methods, connect and deconnect.

In my other file i simply use db::connect() and db::deconnect(). The mysql_close($con) in the deconnect method just doesn't know who $con is.

Since I don't want to instantiate my class static is the only way to go.

Declaring 'private $con' in class db doesn't seem to have an effect.

Any ideas?

class db {

    public static function connect() {
        $dbData = parse_ini_file($_SERVER['DOCUMENT_ROOT'].'/config.ini');

        $con = mysql_connect($dbData['host'],$dbData['user'],$dbData['pass']);
        $db = mysql_select_db($dbData['db']);
        if ((!$con) || (!$db))
            return 0;
        else return 1;
    }

    public static function deconnect() {
        mysql_close($con);
    }

}

© Stack Overflow or respective owner

Related posts about mysql

Related posts about static-methods