title: Why does MySQL return "Access denied for user" error?
body: <p>Here's an error message I am getting:</p>
  
  <blockquote>
    <p>Warning: mysql_connect() [function.mysql-connect]: Access denied for
    user 'user'@'localhost' (using password: YES) in
    /var/www/classes/mysql.class.php on line 29 ERR_DB_CONNECT</p>
  </blockquote>
  
  <p>I am using this database class:</p>
  
  <pre><code>class mysql
  {
  
  public $conn = "";
  public $debug = 0;
  public $queries = NULL;
  
  public function mysql( $dbUser = "user", $dbPass = "pass", $dbName = "database", $dbHost = "localhost" )
  {
      global $config;
      $this-&gt;user = $dbUser;
      $this-&gt;pass = $dbPass;
      $this-&gt;name = $dbName;
      $this-&gt;host = $dbHost;
      if ( $this-&gt;debug == 1 )
      {
          $this-&gt;queries = array( );
          $this-&gt;comments = array( );
      }
      $this-&gt;last_result = FALSE;
      $this-&gt;debug = $config['debug'];
      return TRUE;
  }
  
  public function connect( )
  {
      if ( !( $this-&gt;conn = mysql_connect( $this-&gt;host, $this-&gt;user, $this-&gt;pass ) ) )
      {
          exit( "ERR_DB_CONNECT" );
      }
      $this-&gt;select_db( $this-&gt;name );
      return $this-&gt;conn;
  }
  
  public function select_db( $db )
  {
      if ( !mysql_select_db( $db, $this-&gt;conn ) )
      {
          exit( "ERR_MYSQL_SELECT_DB" );
      }
      $this-&gt;query( "set names utf8" );
  }
  
  public function query( $query, $comment = "" )
  {
      if ( !$this-&gt;conn )
      {
          $this-&gt;conn = $this-&gt;connect( );
      }
      $start = microtime( );
      if ( !( $result = mysql_query( $query, $this-&gt;conn ) ) )
      {
          exit( mysql_error( ) );
      }
      $end = microtime( );
      if ( $this-&gt;debug == 1 )
      {
          list( $usec1, $sec1 ) = explode( " ", $start );
          list( $usec2, $sec2 ) = explode( " ", $end );
          $diff = round( $sec2 - $sec1 + $usec2 - $usec1, 5 );
          $this-&gt;queries[] = $query;
          $this-&gt;comments[] = $comment;
          $this-&gt;queries['time'][] = $diff;
      }
      $this-&gt;last_result = $result;
      return $result;
  } 
  </code></pre>