note 87957 added to function.mysql-real-escape-string

From: Date: Fri, 02 Jan 2009 18:29:18 +0000
Subject: note 87957 added to function.mysql-real-escape-string
Groups: php.notes 
Request: Send a blank email to php-notes+get-148756@lists.php.net to get a copy of this message
Here is another way to escape2sql (as a string or array type) using both methods of 'mysql' and 'mysqli' by reference or returned. Modify to your liking. public function RealEscape2Sql(&$mixedin=NULL,$return=false) { // recursive callback # IN: mixed variable # OUT: (default) reference or returned, if set. if ($return) $mixed = $mixedin; else $mixed = &$mixedin; if (!isset($mixed)) { // if it is NULL return ($return?$mixed:''); } if (is_array($mixed)) { foreach ($mixed as &$value) { $this->RealEscape2Sql($value); } unset($value); } else if (is_string($mixed)) { if ($this->connAs['mysqli']) { $mixed = mysqli_real_escape_string($this->conn,$mixed); } if ($this->connAs['mysql']) { $mixed = mysql_real_escape_string($mixed,$this->conn); } } return ($return?$mixed:''); } Example: # Escape data $db->RealEscape2Sql($report); // is a string, call by reference $decision_counters_esc = $db->RealEscape2Sql($decision_counters,true); // will return and not modify $decision_counters ---- Server IP: 209.41.74.194 Probable Submitter: 74.94.230.73 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-real-escape-string.php Edit -- https://master.php.net/note/edit/87957 Del: integrated -- https://master.php.net/note/delete/87957/integrated Del: useless -- https://master.php.net/note/delete/87957/useless Del: bad code -- https://master.php.net/note/delete/87957/bad+code Del: spam -- https://master.php.net/note/delete/87957/spam Del: non-english -- https://master.php.net/note/delete/87957/non-english Del: in docs -- https://master.php.net/note/delete/87957/in+docs Del: other reasons-- https://master.php.net/note/delete/87957 Reject -- https://master.php.net/note/reject/87957 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#148756) next »