title: Warning: mysqli::mysqli(): (HY000/1045): Access denied for user
body: <p>I am trying to build a database connection with php but i always get the following message:</p>
  
  <blockquote>
    <p>Warning: mysqli::mysqli(): (HY000/1045): Access denied for user 'tgt'@'localhost' (using password: YES) in /opt/lampp/htdocs/s/M152/db.inc.php on line 8
    Die Verbindung zur Datenbank und zum Server konnte nicht hergestellt werden!
    (1045) Access denied for user 'tgt'@'localhost' (using password: YES)
    Warning: mysqli::query(): Couldn't fetch mysqli in /opt/lampp/htdocs/s/M152/index.php on line 7</p>
    
    <p>Fatal error: Call to a member function fetch_object() on null in /opt/lampp/htdocs/s/M152/index.php on line 8</p>
  </blockquote>
  
  <p><b>This is the php script</b></p>
  
  <pre><code>&lt;?php
  // Database connect
  $sql['host'] = 'localhost';
  $sql['user'] = 'tgt';
  $sql['password'] = 'tgt';
  $sql['db'] = 'm_152_1';
  
  $mysqli = new mysqli($sql['host'], $sql['user'], $sql['password'],$sql['db']);
  if ($mysqli-&gt;connect_errno) {
  echo 'Die Verbindung zur Datenbank und zum Server konnte nicht hergestellt werden!&lt;br /&gt;('
  .$mysqli-&gt;connect_errno.') '
  .$mysqli-&gt;connect_error;
  }
  ?&gt;
  </code></pre>
  
  <p>I created tgt@localhost.
  I gave him rights with "GRANT ALL PRIVILEGES ON * . * TO 'tgt'@'localhost';".
  I use Ubuntu 16.04</p>