1

Could someone help me..

I'm trying to escape special chars: " , ' backslash * and other special chars to prevent sql injection.

The problem here is that i'm using php and sql server.

I've searched a lot, but nothing that could really help me, specially with the ' char.

Here is my code:

public function query($sql)
{
    $result = sqlsrv_query($this->connection, $sql);
    return $result;
}
MIlena
  • 257
  • 1
  • 4
  • 13

2 Answers2

4

Don't bother.

Use PDO and prepared statements.

Arkh
  • 8,416
  • 40
  • 45
  • What do you know, "use PDO" indeed is the correct and full answer for this case. Downvote removed :) – Pekka Feb 23 '12 at 11:52
  • I was searching for something simple and faster.. thnx – MIlena Feb 23 '12 at 12:02
  • @Mllena Arkh's suggestion really is the best way to go. Using home-brewn escaping functions isn't a nice idea really. – Pekka Feb 23 '12 at 12:17
  • How is using something already existing not simpler than writing your own solution? Beside that, it would simplify your code too - for instance error handling via exceptions would be waaay easier. – Flavius Feb 23 '12 at 12:45
-4

mysql_real_escape_string http://in3.php.net/manual/en/function.mysql-real-escape-string.php use it

Nishant
  • 3,614
  • 1
  • 20
  • 26