1

I'm trying to connect my database with php, I've got this error:

Warning: mysqli::mysqli(): (HY000/1045): Access denied for user 'typen'@'localhost' (using password: NO) in C:\wamp64\www\Login test 2.0\connectivity.php on line 7

My php code is:

<?php
$servername = "localhost";
$username = "typen";
$password = "";

$conn = new mysqli($servername, $username, $password);
if ($conn->connect_error) {
 die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";

Error notification:

enter image description here

My data base name is: "typen" it's run on a whampserver (localhost) And as far as I know I don't have a password set for my database, I don't even have a password for phpmyadmin.

Pls help me.

M. Eriksson
  • 13,450
  • 4
  • 29
  • 40
Henk
  • 11
  • 1
  • 1
  • 4
  • 1
    Try username as `root` ? – freelancer Dec 02 '17 at 12:36
  • @RishiRaut thnx for your reaction – Henk Dec 02 '17 at 12:38
  • [Your welcome Henk](http://php.net/manual/en/function.mysqli-connect.php) – freelancer Dec 02 '17 at 12:39
  • unfortunately this does not help when I follow your advice i get 2 error messages:Warning: mysqli::mysqli(): php_network_getaddresses: getaddrinfo failed: Host is onbekend. in C:\wamp64\www\Login test 2.0\connectivity.php on line 7 and : Warning: mysqli::mysqli(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Host is onbekend. in C:\wamp64\www\Login test 2.0\connectivity.php on line 7 – Henk Dec 02 '17 at 12:40
  • You need to first check all four `username` `password`, `host` and `dbname`. and share ? – freelancer Dec 02 '17 at 12:41
  • @RishiRaut I don not understand what you mean with "check", I did chek if username pass host and dbname correspond with database and it does. – Henk Dec 02 '17 at 12:49

1 Answers1

2

You said your database name is typen, and generally default database username is root with no password. Try below code:

$servername = "localhost";
$username = "root";
$password = "";
$db = "typen";

$conn = new mysqli($servername, $username, $password,$db);
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
dpaksoni
  • 327
  • 3
  • 17