Jump to content

Database connection errors.


Go to solution Solved by pewe,

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/276878-database-connection-errors/
Share on other sites

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.

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.

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?

 

:tease-03:

 

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.