1

I'm trying to complete my final project for university and I'm having a lot of trouble connecting to a database. When I try to connect to the mysql database it's giving me the following error:

Access denied for user 'B00XXXXXX@localhost'@'SCMSERV2.scm.net' (using password: YES);

even though my password is correct.

I've trolled the interwebs looking for an answer, but everything I have tried has failed.

Here is the connection code I'm using

<?php //PHP 5 +
// database settings
$db_host = '193.xx.xxx.xxx';
$db_username = 'b00XXXXXX';
$db_password = 'XXXXXXXX';
$db_name = 'b00XXXXXX';
$mysqli=mysqli_connect($db_host,$db_username,$db_password);
if(!$mysqli) {
    echo '<h1>Connected to MySQL</h1>';
    //if connected then Select Database.
    $db=mysqli_select_db("b00XXXXXX",$mysqli);
}
else {
    echo '<h1>MySQL Server is not connected</h1>';
}
VolkerK
  • 95,432
  • 20
  • 163
  • 226
NiamhSnow
  • 11
  • 1
  • 1
    Two @s in the error message? That's ... _strange_ . Please add the (relevant) connection code. – VolkerK Apr 09 '16 at 15:15
  • Here is the connection code I'm using; It seems to connect to the database but I have no access, or something along those lines. Connected to MySQL'; //if connected then Select Database. $db=mysqli_select_db("b00XXXXXX",$mysqli); } else { echo '

    MySQL Server is not connected

    ' ; } ?>
    – NiamhSnow Apr 10 '16 at 16:27
  • oh, there's an [edit "button"](http://stackoverflow.com/posts/36518654/edit) – VolkerK Apr 10 '16 at 17:01
  • And you're absolutely positive there's no `@` in your real™ $db_username ? – VolkerK Apr 10 '16 at 17:02
  • As far as I know it's just my log in code for university. Honestly I have no clue why nothing is working! – NiamhSnow Apr 10 '16 at 18:16
  • 1
    So, it's a "yes, there is no @ in the string I assign to $db_username" ? – VolkerK Apr 10 '16 at 18:34

3 Answers3

2

It looks like you have your host details wrong. Your host should be either of these:

  • localhost (i.e. on your local computer)
  • SCMSERV2.scm.net (i.e. on a remote machine, such as a database server)

However it cannot be both.

In general, a good check is to ping the host string - unless pinging is disabled by the firewall, it should reply (and even if it does not, at least your ping program should be able to look up the DNS and display an IP address).

Also, you should be able to use a database client to check the correct credentials: MySQL Workbench (using a GUI) or mysql on the console would both be fine.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • "good check is to ping the machine" - The connection "got through" or there would have been another error message, somethign about "unresolvable address" or "host unreachable" or "connection rejected/timed out". – VolkerK Apr 09 '16 at 15:20
  • That's a good point @VolkerK - I wonder if `B00XXXXXX@localhost` is taken to be a username? The single quotes make it look like that's to be considered as one string (and thus the error is in the username instead). – halfer Apr 09 '16 at 15:22
  • 1
    "if B00XXXXXX@localhost is taken to be a username?" - That sounds like the most likely scenario ;-) – VolkerK Apr 09 '16 at 15:23
0

This either means that the hostname, username or password is incorrect (although if you are sure) or it could mean that the user has not been granted the correct privileges to perform said command.

There is a previous thread on stack overflow here.

You should also just try running example #1 on it's own without your own code to verify the implementation is correct (modified to actual hostname, username and password):

http://php.net/manual/en/function.mysql-connect.php

I would suspect based on your error that your hostname/username is incorrect, it looks as though you have the user set to [username@hostname] rather than just the username on it's own, the error code should be [username@hostname] not [username@hostname1@hostname2].

Community
  • 1
  • 1
Ed Jones
  • 104
  • 6
-1

Often in university the external database access in not allowed. It may be the reason. It is my case in my university.

NathanVss
  • 634
  • 5
  • 16