Technology Blog

Mysql_real_escape_string

by admin on May.21, 2009, under Linux

mysql_logo

Today I was moving some stuff to a live server and Whaamm my code was giving me the following error:

Access denied for user: 'apache@localhost' (Using password: NO)

I debugged it to be the line containing mysql_real_escape_string. But why did it work on the dev server and not the live? My memory immediately kicked in and remembered having similar problems. The code on live was not using persistent connections (not an issue) and the call to mysql_real_escape_string requires a connection to mysql to be open at the time of call. Since the line of code came before any connection to the database was being made, it caused this error.

Make sure you have a connection to mysql open before calling this method!

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • StumbleUpon
  • TwitThis

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...