0

I am trying to connect to a mysql database in my PHP script, this is my code

$link = mysqli_connect($dbServer, $dbUsername, $dbPassword, $dbUsername);

(The variables are stored in another file)

When I try to connect to the database I get:

Warning: mysqli_connect(): Access denied

However, when I do the link and I use plaintext strings, the connection works. I have checked and all of the variables that I have used can be acessed in this file but for some reason it still isn't working. Does anyone have any idea what the issue is?

Many Thanks

Onglo
  • 181
  • 1
  • 11
  • Is that the only message you get? usually you get `access denied for user...` because of incorrect username or password? http://stackoverflow.com/questions/25174183/warning-mysqli-connect-hy000-1045-access-denied-for-user-usernameloca turn on `error_reporting(E_ALL);` why are you reusing $dbUsername? isn't that supposed to be the database instead? –  Dec 16 '16 at 22:45
  • The whole error message is this: Warning: mysql_connect(): Access denied for user '***'@'**.*.*.**' (using password: YES) in /home/sites/*******/public_html/****/userSignUpPage/index.php on line 120 – Onglo Dec 16 '16 at 22:48
  • See the link I provided in my first comment.. It should answer your question. If not, comment here again and I will try to help you resolve your issue. –  Dec 16 '16 at 22:49
  • The web host that I use means that the database name is the same as the database username. I know that this is the case because when I type in these values in plaintext the connection works, it only gives me this error when I use the variables instead of plaintext – Onglo Dec 16 '16 at 22:51
  • Try to echo out the variables to see if the content of the variables is correct? –  Dec 16 '16 at 22:52
  • I have, it is all as it's supposed to be – Onglo Dec 16 '16 at 22:54
  • I cannot determine what the problem could be. I don't understand what how the content of a variable could differ from plain text, unless special characters are used... but that would usually result in an error. –  Dec 16 '16 at 22:59
  • 1
    Ok no problem, it's probably something stupid that I'm doing, I will continue to debug. Thanks for your help! – Onglo Dec 16 '16 at 23:00
  • Show the rest of the code, what's happening before this? Where are you setting those vars? Double check the case of the vars, since you seem to be using a capital after "db", check they all match up. If you still have trouble, feel free to make a new one and link me to it. – NaughtySquid Dec 16 '16 at 23:30

0 Answers0