0

I am trying to build a database connection with php but i always get the following message:

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

Fatal error: Call to a member function fetch_object() on null in /opt/lampp/htdocs/s/M152/index.php on line 8

This is the php script

<?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->connect_errno) {
echo 'Die Verbindung zur Datenbank und zum Server konnte nicht hergestellt werden!<br />('
.$mysqli->connect_errno.') '
.$mysqli->connect_error;
}
?>

I created tgt@localhost. I gave him rights with "GRANT ALL PRIVILEGES ON * . * TO 'tgt'@'localhost';". I use Ubuntu 16.04

Dharman
  • 21,838
  • 18
  • 57
  • 107
D.Wyss
  • 1
  • 1
  • 3

0 Answers0