title: Access denied error when using mysql_real_escape_string()
body: <p>i am trying escape some data before it goes into my database, but i keep getting this error:</p>
  
  <pre><code>Warning: mysql_real_escape_string(): Access denied for user 
  </code></pre>
  
  <p>Now this would usually suggest that i have not connected to the database (it also states (using password: NO)). </p>
  
  <p>I was a little confused by this because when connecting to a database i have a 'die' clause so if it fails to connect i get told about it. So i tested this theory by running a simple query in the same function that im trying to escape the data and it works just fine.</p>
  
  <p>So why on earth won't the escape method work or get a connection to the database. I did notice that the user the error states is not the user i use to access the database its something like 'www-data@localhost'. Could it be trying to log in with a different user, if so why and how? Because i another area of my website the escape function works just fine and i didn't do anything special to make it work, just added the code into my web page.</p>
  
  <p>thanks for the help. </p>
  
  <p>Are there any other ways of sanitizing my code?</p>
  
  <p>Okay, so here we go, when the user submits the form, i use AJAX to collect the data and put it into an obj to post(JSON encoding) it to the first PHP script which is here:</p>
  
  <p><a href="http://codepad.org/kGPljN4I" rel="nofollow">http://codepad.org/kGPljN4I</a></p>
  
  <p>This script checks all the data is there and then calls a function to add it to the database</p>
  
  <p>this Mysql class is called to escape the data and then add a new record to the database, when and instance of the class is made it makes a connection to the database:</p>
  
  <p><a href="http://codepad.org/wwGNrTJm" rel="nofollow">http://codepad.org/wwGNrTJm</a></p>
  
  <p>The third file is for constants, it holds the information for the database like pass, user and so on:</p>
  
  <p><a href="http://codepad.org/dl0QQbi9" rel="nofollow">http://codepad.org/dl0QQbi9</a></p>
  
  <p>any better?</p>
  
  <p>thanks again for the help.</p>