note 97933 added to function.mysql-real-escape-string
| From: | manixrock-~-gmail~-~com at osu1 dot php dot net | Date: | Sun, 16 May 2010 23:07:42 +0000 |
| Subject: | note 97933 added to function.mysql-real-escape-string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-169312@lists.php.net to get a copy of this message | ||
I've come up with an easy way to more easily escape things in an sql query. The simpler things
are, the lower the chance that you'll forget to escape something. I use a helper class:
<?php
class MysqlStringEscaper
{
function __get($value)
{
return mysql_real_escape_string($value);
}
}
$str = new MysqlStringEscaper;
?>
then whenever I run a query I can simply do:
<?php
mysql_query("SELECT * FROM users WHERE name LIKE '{$str->$name}' LIMIT 10");
?>
This way it's easy to see what the variable is escaped as (other instances like $int or $list
could be implemented), it's inline and it only changes the variable when it's inserted
into the query.
----
Server IP: 69.147.83.197
Probable Submitter: 188.27.69.161
----
Manual Page -- http://www.php.net/manual/en/function.mysql-real-escape-string.php
Edit -- https://master.php.net/note/edit/97933
Del: integrated -- https://master.php.net/note/delete/97933/integrated
Del: useless -- https://master.php.net/note/delete/97933/useless
Del: bad code -- https://master.php.net/note/delete/97933/bad+code
Del: spam -- https://master.php.net/note/delete/97933/spam
Del: non-english -- https://master.php.net/note/delete/97933/non-english
Del: in docs -- https://master.php.net/note/delete/97933/in+docs
Del: other reasons-- https://master.php.net/note/delete/97933
Reject -- https://master.php.net/note/reject/97933
Search -- https://master.php.net/manage/user-notes.php