amrithk Posted June 7, 2007 Share Posted June 7, 2007 Hi, I am new to PHP and MYSQL. I recently installed both PHP and MYSQL (the community edition) on my computer and I have been trying to use PHP to connect to and access MYSQL (instead of using the MYSQL command line). I used the mysql_connect() function on a test script but I am getting the following error message when I test the script. Warning: mysql_connect() [function.mysql-connect]: Access denied for user ' '@'localhost' (using password: YES) in filename on line 10. I understand that I am being denied access because I have not submitted the right credentials. However, I am testing this code on my local computer where I have full privileges. What might be the reasons I am getting this message? What are the possible solutions? Do I need to configure mysql such that it recognizes that I am using it on a local computer? Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/54640-using-php-to-connect-to-mysql-server/ Share on other sites More sharing options...
chigley Posted June 7, 2007 Share Posted June 7, 2007 Paste your code please? Quote Link to comment https://forums.phpfreaks.com/topic/54640-using-php-to-connect-to-mysql-server/#findComment-270205 Share on other sites More sharing options...
amrithk Posted June 7, 2007 Author Share Posted June 7, 2007 This was my code. <?php mysql_connect("localhost"," ","stargate") or die("Could not connect"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/54640-using-php-to-connect-to-mysql-server/#findComment-270277 Share on other sites More sharing options...
per1os Posted June 7, 2007 Share Posted June 7, 2007 Your username is blank. // original mysql_connect("localhost"," ","stargate") or die("Could not connect"); //mysql_connect($HOST, $USERNAME, $PASSWORD) that is how it should be setup // corrected mysql_connect("localhost","stargate", " ") or die("Could not connect"); Try that. Quote Link to comment https://forums.phpfreaks.com/topic/54640-using-php-to-connect-to-mysql-server/#findComment-270279 Share on other sites More sharing options...
amrithk Posted June 7, 2007 Author Share Posted June 7, 2007 I tried different combinations for the function. I entered my username and password, just my username, just my password and did not enter anything but none of these combinations seemed to work. I don;t think its a problem with my username and password because when I type http://localhost on my web browser, I supply the same user name and password to access all the files. What might be the problem? Quote Link to comment https://forums.phpfreaks.com/topic/54640-using-php-to-connect-to-mysql-server/#findComment-270311 Share on other sites More sharing options...
per1os Posted June 7, 2007 Share Posted June 7, 2007 I do not know, it has to be something with the username and password. www.php.net/mysql_connect If it wasn't it wouldn't return the error message it did. Quote Link to comment https://forums.phpfreaks.com/topic/54640-using-php-to-connect-to-mysql-server/#findComment-270312 Share on other sites More sharing options...
SkyRanger Posted June 7, 2007 Share Posted June 7, 2007 OK, you may think this is a stupid question, but you would be surprised. Are you using cPanel? Did you connect the username to that database? You would be surprised to see how many people have done that, I have done that. Quote Link to comment https://forums.phpfreaks.com/topic/54640-using-php-to-connect-to-mysql-server/#findComment-270323 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.