0

I just created a database by importing SQL file. I have created users added privileges but when I try to connect by PDO it throws this error:

(Uncaught PDOException: SQLSTATE[28000] [1045] Access denied for user xxx)

even though the username and password is correct.

I am having hard time to solve this. I deleted the database and also created again another database but it seems nothing will work.

$host = "example.com";
$db = "sgOnlineSystem";
$user = "xxx";
$pass = "xxxx";
$conn = new PDO("mysql:host=$host;dbname=$db", $user, $pass);

I have no idea what's going wrong. enter image description here

Alessio Cantarella
  • 5,077
  • 3
  • 27
  • 34
Francisco
  • 63
  • 8
  • try printing error via mysql_error() – Shubham Aug 05 '18 at 11:53
  • hi.. here is the mysql_error() 'Connection failed: Access denied for user 'admin0198'@'ip-160-153-162-20.ip.secureserver.net' (using password: YES)' – Francisco Aug 05 '18 at 12:03
  • is your host set to `any` or `ip-160-153-162-20.ip.secureserver.net` . [This might help you](https://stackoverflow.com/questions/14779104/how-to-allow-remote-connection-to-mysql) – Madhan Varadhodiyil Aug 05 '18 at 12:14
  • Francisco, try connecting as `root` with the known root password, to see if there are any other issues with your database server. You can also try connecting via the `mysql` console to eliminate any issues relating to PHP. – halfer Aug 05 '18 at 12:15
  • @halfer ok noted thanks. – gil Aug 05 '18 at 12:18

1 Answers1

0

Try to create a new user like that:

GRANT ALL PRIVILEGES ON sgOnlineSystem.* TO 'admin0198'@'ip-160-153-162-20.ip.secureserver.net' IDENTIFIED BY 'YOURPASSHERE';

FLUSH PRIVILEGES; // This is also important to do

--

And then just try to connect with command line tool from your remote host, not PHP. If it works than PHP code will work also.

gegirhasut
  • 3
  • 1
  • 3
  • hi. i am totally new to command line. if you could, please advise what to type in command line to connect. here is the actual/full error that shows. "Stack trace: #0 /home/ry91p8weag4x/public_html/Conn.php(9): PDO->__construct('mysql:host=sg...', 'cajetan', 'hj03865684') #1 {main} thrown in /home/ry91p8weag4x/public_html/Conn.php on line 9" – Francisco Aug 05 '18 at 12:58