tags:

views:

156

answers:

1

I have a login page that gets the username and pwd and sanitises them before passing them to DB.

this is done through a function:

function make_safe($text) {
  open_db_connection(); //this opens another connection!

  if(get_magic_quotes_gpc()) {
    $text = stripslashes($text);
  }
  $text = mysql_real_escape_string($text);
  return $text;
}

this function is called from a script that already has an open connection, but still, I found that I have to open another connection INSIDE ´make___safe()´ to make it work (otherwise I get a "Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user blablabla@localhost ..."

I was wondering:

1) when I call make_safe, I already have an open connection - why is it not enough??

2) what are the problems in opening multiple connections?

thanks, patrick

+1  A: 

I think you may need to supply the second argument to mysql_real_escape_string.

MZB
The second parameter is the ( resource $linkIdentifier ) by default it will use the last open connection, but you could specify an older connection.
mediaslave