note 113094 deleted from mysqli.real-escape-string by cmb
| From: | cmb@php.net | Date: | Wed, 24 Jul 2019 13:34:39 +0000 |
| Subject: | note 113094 deleted from mysqli.real-escape-string by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211694@lists.php.net to get a copy of this message | ||
Note Submitter: kit dot lester at mail dot com
----
A PHP application I'm working on has many pages which (long story) need to share a PHP API that
looks after a MySQL database. Easiest way was to have the app pages AJAX to the API .PHPs.
That means having the JavaScript of the AJAX encodeURIComponent(...) relevant bits of any data to be
sent via HTTP POST and GET requests - space as %20 and so on.
But the SQL also needed real_escape_string(...) of the same data.
So I had the issue of whether to do the real_escape_string *before* or *after* encodeURIComponent?
in other words in the application PHP or API PHP? Do either of the encodings mangle the other?
The real_escape_string would be "cleaner" in the API, both in principle, and because it
needs an instance of mysqli class and there are are unlikely to be instances in the app.
(real_escape_string needs an instance because it's not a *static* function - I don't know
why).
But I suspect that "in the API" is the mangle-avoiding place: the JavaScript encode gets
undone by the HTTP call to whichever API element, then the element can safely real_escape_string
what is to be put into the database.
Comments would be appreciated.