note 49979 added to function.pg-update
| From: | skippy at zuavra dot net | Date: | Mon, 14 Feb 2005 15:09:09 +0000 |
| Subject: | note 49979 added to function.pg-update | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85003@lists.php.net to get a copy of this message | ||
Beware of the following: pg_insert() and pg_update() are adding slashes to all character-like fields
they work with. This makes them SQL injection super-safe, but there are unwanted consequences, as
follows:
If you have a regular setup with magic_quotes_gcp=On, and you use pg_insert() or pg_update(), you
will end up with fields that look as if you used addslashes() twice. To solve this, you can use
stripslashes() on the data just before using it with pg_insert() or pg_update().
There's another alternative, which seems better to me. Why make yourself crazy all over the
code, adding slashes, stripping slashes, worrying whether magic_quotes_gpc is on or off and so on
and so forth? Why do this, when the only place you actually need those slashes is right when you
push the data into the database?
So why not get rid of your addslashes() and stripslashes() from all over your code, and turn
magic_quotes_gcp off. As long as you always use pg_insert() and pg_update() to do your DB work,
you're SQL-injection safe AND slash-headache free.
----
Manual Page -- http://www.php.net/manual/en/function.pg-update.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49979
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49979&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49979&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49979&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49979&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49979&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49979&report=yes
Search -- http://master.php.net/manage/user-notes.php