title: PHP cant connect to MySQL
body: <pre><code>$link = mysql_connect('localhost', $username, $password);
  if (!$link) 
  {
       die('Could not connect: ' . mysql_error());
  }
  </code></pre>
  
  <p>I get this error:</p>
  
  <p>Could not connect: Access denied for user 'www-data'@'localhost' (using password: NO)</p>
  
  <p>Why?</p>
  
  <p>Edit:</p>
  
  <p>
  
  <pre><code>$username="root";
  $password="root";
  $database="test";
  
      function Save($name)
      {
          $link = mysql_connect('localhost', $username, $password);
          if (!$link) {
              die('Could not connect: ' . mysql_error());
          }
          @mysql_select_db($database) or die( "Unable to select database");
          $query = "INSERT INTO test (name)" .
                   "VALUES ('" . $name . "')";
          mysql_query($query);
          mysql_close();
      }
  </code></pre>