Warning: mysqli::mysqli(): (HY000/1045): Access de

2019-03-03 20:57发布

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.

标签: php mysql mysqli
1条回答
Summer. ? 凉城
2楼-- · 2019-03-03 21:13

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";
查看更多
登录 后发表回答