note 95501 deleted from function.mysql-real-escape-string by danbrown
| From: | danbrown@php.net | Date: | Wed, 06 Jan 2010 15:51:31 +0000 |
| Subject: | note 95501 deleted from function.mysql-real-escape-string by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-164685@lists.php.net to get a copy of this message | ||
Note Submitter: xero dot nu at gmail dot com
Reason: useless
----
preventing SQL injections is important.
but the mysql_real_escape_string function
is useless when connecting to a MS SQL
or oracle database. the following function
basically replicates the functionality of
mysql_real_escape_string in native php
code that can be called with or with out
a database connection present.
/**
* SQL injection protection function
* the function takes a string parameter and removes
* any harmful characters in the string that could be
* used to hack or attack the database.
*
* @param string $param
* @return string
*/
public function attackCheck($param) {
return strtr($param, array(
"\x00" => '\x00',
"\n" => '\n',
"\r" => '\r',
'\\' => '\\\\',
"'" => "\'",
'"' => '\"',
"\x1a" => '\x1a'
));
}