note 113094 added to mysqli.real-escape-string

From: Date: Wed, 28 Aug 2013 23:35:59 +0000
Subject: note 113094 added to mysqli.real-escape-string
Groups: php.notes 
Request: Send a blank email to php-notes+get-196109@lists.php.net to get a copy of this message
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. ---- Server IP: 69.147.83.199 Probable Submitter: 109.145.176.87 ---- Manual Page -- http://php.net/manual/en/mysqli.real-escape-string.php Edit -- https://master.php.net/note/edit/113094 Del: integrated -- https://master.php.net/note/delete/113094/integrated Del: useless -- https://master.php.net/note/delete/113094/useless Del: bad code -- https://master.php.net/note/delete/113094/bad+code Del: spam -- https://master.php.net/note/delete/113094/spam Del: non-english -- https://master.php.net/note/delete/113094/non-english Del: in docs -- https://master.php.net/note/delete/113094/in+docs Del: other reasons-- https://master.php.net/note/delete/113094 Reject -- https://master.php.net/note/reject/113094 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#196109) next »