pewe Posted April 12, 2013 Share Posted April 12, 2013 I have a php script (which I did not write as I have limited coding knowledge) which is returning database connection errors. At the front of the script is the following connection instruction //connect to database define('DB_SERVER', 'localhost'); define('DB_USER', 'username'); define('DB_PASSWORD', 'password'); define('DB_NAME', 'database'); @$conn = mysql_connect (DB_SERVER, DB_USER, DB_PASSWORD); mysql_select_db (DB_NAME,$conn); if(!$conn){ die( "Sorry! There seems to be a problem connecting to our database."); } The next part of the script is a form to select a file for upload. There are no errors at this part of the script. However as soon as the 'submit' button is selected and the file uploaded, there is an error Errors: Access denied for user 'username'@'localhost' (using password: YES) The user specified has full database rights so I am confused as to why this error occurs. How can I determine where the problem is in the script. Thanks for any contribution towards finding a solution. Quote Link to comment Share on other sites More sharing options...
Barand Posted April 12, 2013 Share Posted April 12, 2013 Errors: Access denied for user 'username'@'localhost' (using password: YES) It could be that your username and password are not valid for the server. Quote Link to comment Share on other sites More sharing options...
pewe Posted April 12, 2013 Author Share Posted April 12, 2013 It could be that your username and password are not valid for the server. That's the confusing part - they are - I set up the database and I have other scripts talking to the database which all work fine. Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 12, 2013 Share Posted April 12, 2013 Try removing the error supressor (@) Quote Link to comment Share on other sites More sharing options...
pewe Posted April 12, 2013 Author Share Posted April 12, 2013 Try removing the error supressor (@) Forgive my lack of knowledge - I'm not sure, where would I remove this '@' from? Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 12, 2013 Share Posted April 12, 2013 Uhm. From your code. Quote Link to comment Share on other sites More sharing options...
pewe Posted April 12, 2013 Author Share Posted April 12, 2013 Uhm. From your code. Uhm - thanks for the clarification - I thought you might have meant remove it from the fridge !! I did start my query stating I have limited coding knowledge Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 12, 2013 Share Posted April 12, 2013 Look at your code and find the one place that the @ symbol is typed. You don't have to even know anything about programming to do that, you just need to have eyes and fingers to look, move the cursor there and hit delete. Quote Link to comment Share on other sites More sharing options...
pewe Posted April 12, 2013 Author Share Posted April 12, 2013 Look at your code and find the one place that the @ symbol is typed. You don't have to even know anything about programming to do that, you just need to have eyes and fingers to look, move the cursor there and hit delete. There are in fact 9 places in the code where the @ symbol appears - none of which have any wording which relates to an error - $res =@mysql_query($sql) (x 4) - @mysql_escape_string($this->file_name)); - "LOAD DATA INFILE '".@mysql_escape_string($this->file_name). "' INTO TABLE `".$this->table_name. "` FIELDS TERMINATED BY '".@mysql_escape_string($this->field_separate_char). "' OPTIONALLY ENCLOSED BY '".@mysql_escape_string($this->field_enclose_char). "' ESCAPED BY '".@mysql_escape_string($this->field_escape_char). None of them mention 'error' or appear (to me) to relate to error. I found these using my eyes, but before I start learning how to use my fingers to look, learn what a cursor is, or what delete means, I first need to understand which @ would relate to an error supressor. Quote Link to comment Share on other sites More sharing options...
Barand Posted April 12, 2013 Share Posted April 12, 2013 http://php.net/manual/en/language.operators.errorcontrol.php Quote Link to comment Share on other sites More sharing options...
pewe Posted April 12, 2013 Author Share Posted April 12, 2013 http://php.net/manual/en/language.operators.errorcontrol.php Thanks Barand - that makes sense. I removed the error control and still get the error message Errors: Access denied for user 'username'@'localhost' (using password: YES) If I misspell the database username I get a message (set in the script) to the effect that the script cannot connect. Once I correct the spelling mistake I get further and the upload form is displayed. As soon as the file uploads the script stops with the above error at the point where it should be producing a list of the uploaded file headers and a list of the field headers from the mysql table. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 13, 2013 Share Posted April 13, 2013 What is your operating system? Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 13, 2013 Share Posted April 13, 2013 The code you posted only had one. Leave the smart alecing to the pros Did you seriously claim you don't know what "delete" means either? Quote Link to comment Share on other sites More sharing options...
pewe Posted April 13, 2013 Author Share Posted April 13, 2013 What is your operating system? Operating system: Linux PHP: 5.3.22 [2013-04-13 02:02:51] MySQL: 5.1.68-cll [2013-04-12 20:02:51] The code you posted only had one. Not sure I'm with you on that. Which code are you referring to. The code I posted above had 9 @ signs in it. Did you seriously claim you don't know what "delete" means either? It's 2 am here now and I have an early start in the morning (hospital run to visit my son). I have attached a copy of the file for anyone who may have the time (and hopefully inclination) to cast an eye - just in case there is an obvious and simple answer. Quick_CSV_import.zip Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 13, 2013 Share Posted April 13, 2013 I can't open that on my mobile device. If you aren't already using one file for your connection, copy it from one that works, save it as connect.php and use require_once on the file that's having issues. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 13, 2013 Share Posted April 13, 2013 Operating system: Linux Sometimes I'm using this guide - tested. Instead WHERE User='root', you sould use WHERE User='userName'; Quote Link to comment Share on other sites More sharing options...
Solution pewe Posted April 13, 2013 Author Solution Share Posted April 13, 2013 Ok, I found the problem - nothing to do with the database access, it was a script function that MySql didn't like. So can now move on and test out the rest of the script. Quote Link to comment 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.