mysql_connect() acces denied for system@localhost(using password NO)

Posted by user309381 on Stack Overflow See other posts from Stack Overflow or by user309381
Published on 2010-04-16T01:28:29Z Indexed on 2010/04/16 1:33 UTC
Read the original article Hit count: 270

Filed under:

class MySQLDatabase { public $connection; function _construct() { $this->open_connection(); } public function open_connection() { $this->connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS); if(!$this->connection) { die("Database Connection Failed" . mysql_error()); } else { $db_select = mysql_select_db(DB_NAME,$this->connection); if(!$db_select) { die("Database Selection Failed" . mysql_error()); } } } function mysql_prep($value) { if (get_magic_quotes_gpc()) { $value = stripslashes($value); } // Quote if not a number if (!is_numeric($value)) { $value = "'" . mysql_real_escape_string($value) . "'"; } return $value;

}
public function close_connection()
{
    if(isset($this->connection))
    {
        mysql_close($this->connection);
        unset($this->connection);
    }
}
public function query(/*$sql*/)
{
    $sql = "SELECT*FROM users where id = 1";
    $result = mysql_query($sql);
    $this->confirm_query($result);
    //return $result;
    while( $found_user = mysql_fetch_assoc($result))
    {
     echo $found_user ['username'];
    }

}
private function confirm_query($result)
{
    if(!$result)
    {
        die("The Query has problem" . mysql_error());
    }
}

}

$database = new MySQLDatabase(); $database->open_connection(); $database->query(); $database->close_connection();

?>

© Stack Overflow or respective owner

Related posts about php