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

2019-03-03 21:20发布

问题:

This question already has an answer here:

  • Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO) [duplicate] 2 answers
  • PHP MySql (1045) Access Denied For User 4 answers
  • MySQL ERROR 1045 (28000): Access denied for user 'bill'@'localhost' (using password: YES) 33 answers
  • “Connect failed: Access denied for user 'root'@'localhost' (using password: YES)” from php function 10 answers

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:

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.

回答1:

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";


标签: php mysql mysqli