Error: SQLSTATE [28000] [1045] Access denied for user 'digital_chuser' @ 'localhost' (using password: YES)

0

I have the following problem, I am trying to connect to the database with pdo in HostGator but I receive the following error:

  

Error: SQLSTATE [28000] [1045] Access denied for user   'digital_chuser' @ 'localhost' (using password: YES)

My connection code is:

<?php
try {
    $con = new PDO('mysql:host=localhost;dbname=digital_chdb','digital_chevuser','TK$JhM,XV&tD>');
} catch (PDOException $e) 
{
    echo 'Error: '. $e->getMessage();
}

?>

At the end I have this other message:

  

Fatal error: Call to a member function prepare () on null in   /home3/digital/public_html/chevistar/index.php on line 6

I have created the database and user in the MySQL Databases section and added that user to the database, when I go to PHPMYADMIN I see the database created with their tables, however when I check MYSQL Databases it appears as a database empty is not there is the track.

    
asked by Qarilucas 08.03.2018 в 18:41
source

3 answers

1

Hi, how are you really? I thank you very much for your answers. I have found the problem and I have solved it. It is an issue that happens through the connection to the database, specifically in the definition of the host. There are two solutions to this problem, I hope you can use them if you encounter this type of error:

1.- The first and easiest solution is to define the host = localhost by its equivalent ip that is:

<?php
try {
$con = new PDO('mysql:host=127.0.0.1;dbname=digital_chdb','digital_chevuser','XXXXXXXXXXXXXX');
} catch (PDOException $e) 
{
echo 'Error: '. $e->getMessage();
}
?>

Localhost is replaced by 127.0.0.1, which is the ip that refers to the host on which the site is hosted.

The second solution is to replace localhost with the server ip, the complicated thing with this form is that this address is not visible in the c-panel or in any part of the hired host, so it will be necessary to contact the server directly. with host staff to give you this information.

    
answered by 13.03.2018 в 17:52
0

The second error is a consequence of the first, so let's concentrate on that one. The first, indicates that the connection to the database in localhost could not be made with the user and keys indicated.

This usually happens when the credentials entered are erroneous, that is, wrong username or password.

Seeing that in the code you share you use a different user (digital_chevuser) that is indicated in the error message (digital_chuser) I would recommend that you check which one is correct and try the connection again.

    
answered by 10.03.2018 в 17:02
0

The data that you pass to your connection; can be in two ways: both local and remote, I explain

1.- Local (referring to your own computer equipment)

<?php
try {
    $con = new PDO('mysql:host=localhost;dbname=digital_chdb','digital_chevuser','TK$JhM,XV&tD>');
} catch (PDOException $e) 
{
    echo 'Error: '. $e->getMessage();
}

?>
  

Where, as you can notice in mysql:host=localhost , I indicate that   point to an installation inside the computer itself

2.- Remote: Referring for example to the IP of the server where the database manager that will contain your database is hosted

<?php
try {
    $con = new PDO('mysql:host=192.168.0.12;dbname=digital_chdb','digital_chevuser','TK$JhM,XV&tD>');
} catch (PDOException $e) 
{
    echo 'Error: '. $e->getMessage();
}

?>
  

Where, as you can notice in mysql:host=192.168.0.12 , I indicate that   connect to a remote IP address that corresponds to the server's   that you have rented

For the specific error

You are indicating that you have an error because you have written a password, what you should do is leave that space without any assigned value

EXAMPLE

$con = new PDO('mysql:host=localhost;dbname=digital_chdb','digital_chevuser','');
  

As you can see the password space, I leave it without any   value and without space in the middle of the single quotes so that it   interpret that there is no assigned value

    
answered by 08.03.2018 в 18:44