Error, Problem with XAMPP

0

I have this code in PHP:

<?php 
    include ('parametros.php');
    $conexion = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);

    if (!$conexion) {
        echo "hay pedo";
    }else{
        echo "puro fierro :v";
    }
 ?>

When I enter the browser, I get this error:

  

Warning: mysqli_connect (): (HY000 / 1045): Access denied for user   'I' @ 'localhost' (using password: YES) in C: \ xampp \ htdocs \   Back End - Students \ stop \ php \ logica \ conexion.php on line 6   Connection failed: Access denied for user 'me' @ 'localhost' (using   password: YES))

(Neither with that user nor with root with the password '')

When I see the MySql this appears like this:

My colleagues have the image in black letters, they appear in red.

I searched for the solution and it did not work for me. Besides how to look for that type of error.

PHP 7

    
asked by Jose Luis 15.10.2017 в 05:00
source

3 answers

1

The user you are trying to use to connect to mysql does not exist, the password is incorrect, or you are not allowed to access from localhost.

You can change the user or in case there is no user created with the password you have defined in DB_PASSWORD.

for the above run on phpmyadmin:

CREATE USER 'yo'@'localhost' IDENTIFIED BY 'mypassword';
GRANT USAGE ON *.* TO 'yo'@'localhost';
GRANT ALL ON *.* TO 'yo'@'localhost';

If the value of DB_PASSWORD is "mypassword" and the page is hosted on the same server as the mysql server. the above should work.

Another option according to the image that the phpmyadmin is to use the user without password.

    
answered by 19.10.2017 / 15:59
source
0

Try this.

    <?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', 'xxxx');
define('DB_DATABASE', 'sample_db');
$connection = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD) or die("Error " . mysqli_error());
$database = mysqli_select_db(DB_DATABASE) or die(mysql_error());
mysqli_set_charset("utf8",$connection);
?>

And I recommend that you use pdo, remember that the php versions influence a lot.

    
answered by 15.10.2017 в 05:10
0

The solution I found for my case was:

include ('parametros.php');
    $conexion = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE,1512);

As you can see, I added "1512" which was the new port I added when configuring the Xamp.

    
answered by 17.02.2018 в 18:30