0

I had a function that escapes data before performing SQL statements. Now Problem is I have 4 databases, So how can I pass database object to function.

function escape($what) 
{
global $db;

foreach ($what as $variable => $value)
{
    if (is_string($value) || is_numeric($value))
    {

        $GLOBALS[$variable] = $db->real_escape_string();
    }
    else
    {
        $GLOBALS[$variable] = $value;
    }
}
}
4
  • what do you mean by database object ? Commented Sep 6, 2012 at 20:02
  • $GLOBALS? Have you heard of PDO? Commented Sep 6, 2012 at 20:02
  • It's time to go for PDO friend. Commented Sep 6, 2012 at 20:04
  • To escape sql statements, its recommended to use prepared statements. Al the escaping is done for you that way so you dont have to invent the wheel again. Look for mysql::prepare(); On php.net Commented Sep 6, 2012 at 20:05

1 Answer 1

1

Just add another parameter to your function:

function escape($db, $what)

And change the calls to the function.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.