Warning: mysqli_connect(): (HY000/1045): Access denied for user 'username'@'localhost' (using password: YES)

前端 未结 21 2146
春和景丽
春和景丽 2020-11-22 06:31

Warning: mysqli_connect(): (HY000/1045): Access denied for user \'username\'@\'localhost\' (using password: YES) in C:\\Users\\xampp\\htdocs\\PHP_Login_Script

相关标签:
21条回答
  • 2020-11-22 07:17

    There is a typo error in define arguments, change DB_HOST into DB_SERVER and DB_USER into DB_USERNAME:

    <?php
    
        define("DB_SERVER", "localhost");
        define("DB_USERNAME", "root");
        define("DB_PASSWORD", "");
        define("DB_DATABASE", "databasename");
        $db = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
    
    ?>
    
    0 讨论(0)
  • 2020-11-22 07:20

    Look at your code You defined DB_HOST and querying DB_SERVER. DB_USER and DB_USERNAME Use this code

    define("DB_SERVER", "localhost");
    define("DB_USER", "root");
    define("DB_PASSWORD", "");
    define("DB_DATABASE", "databasename");
    
    $connect = mysqli_connect(DB_SERVER , DB_USER, DB_PASSWORD, DB_DATABASE);
    
    0 讨论(0)
  • 2020-11-22 07:21

    try

    define("DB_PASSWORD", null);
    

    and those are warnings try

    $db = @mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
    

    But i will recommend you to set a root password

    0 讨论(0)
  • 2020-11-22 07:22

    I had this error trying to connect with a different user than root I'd set up to limit access.

    In mysql I'd set up user MofX with host % and it wouldn't connect.

    When I changed the user's host to 127.0.0.1, as in 'MofX'@'127.0.0.1', it worked.

    0 讨论(0)
  • 2020-11-22 07:23

    The same issue faced me with XAMPP 7 and opencart Arabic 3. Replacing localhost by the actual machine name reslove the issue.

    0 讨论(0)
  • 2020-11-22 07:25

    I have fixed a few things here, the "DB_HOST" defined here should be also DB_HOST down there, and the "DB_USER" is called "DB_USER" down there too, check the code always that those are the same.

    <?php
        define("DB_HOST", "localhost");
        define("DB_USER", "root");
        define("DB_PASSWORD", "");
        define("DB_DATABASE", "");
    
        $db = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
    ?>
    
    0 讨论(0)
提交回复
热议问题