title: unable to connect MYSQL using PHP "Access denied for user ''@'localhost' (using password: NO)"
body: <p>I am trying to connect php and mysql.</p>
  
  <p>Here is the <strong>code :</strong></p>
  
  <pre><code>&lt;?php
  
  $response=array();
  require_once 'C:\wamp\www\android_connect\db_connect.php';
  $db=new DB_CONNECT();
  
  
  $result=mysql_query("select * from product")or die(mysql_error());
  
  if(mysql_num_rows($result)&gt;0)
  {
      $response["products"]=array();
  
      while($row=mysql_fetch_array($result))
      {
          $product=array();
          $product["pid"]=$row["pid"];
          $product["name"]=$row["name"];
          $product["price"]=$row["price"];
          $product["description"]=$row["description"];
  
          array_push($response["products"],$product);
      }
      $response["success"]=1;
  }
  else
  {
      $response["success"]=0;
      $response["message"]="No products found";
  }
  echo json_encode($response);
  
  ?&gt;
  </code></pre>
  
  <p>When i am trying to open the file using <code>WAMP</code> installed on my computer it throws the following <strong>error :</strong></p>
  
  <pre><code>Warning: mysql_query(): Access denied for user ''@'localhost' (using password: NO) in C:\wamp\www\android_connect\get_all_products.php on line 8
  
  Warning: mysql_query(): A link to the server could not be established in C:\wamp\www\android_connect\get_all_products.php on line 8
  </code></pre>
  
  <p>In my case <strong>line 8</strong> is:</p>
  
  <pre><code>$result=mysql_query("select * from product")or die(mysql_error());
  </code></pre>
  
  <p>and the <strong>code</strong> of <code>db_connect</code> is as follows:</p>
  
  <pre><code>&lt;?php
  
  class DB_CONNECT
  {
  
      function _construct()
      {
          $this-&gt;connect();
      }
  
      function _destruct()
      {
          $this-&gt;close();
      }
  
      function connect()
      {
          $con=mysql_connect('localhost','root','kamani') or die (mysql_error());
          $db=mysql_select_db('mobileinventory') or die (mysql_error());
          return $con;
      }
  
      function close()
      {
          mysql_close();
      }
  }
  
  ?&gt;
  </code></pre>
  
  <p>To complete see the error here i am uploading its snap.
  <img src="https://i.stack.imgur.com/IH34b.jpg" alt="enter image description here"></p>
  
  <p>I am <strong>unable to solve</strong> this <strong>error</strong>.</p>