note 87957 deleted from function.mysql-real-escape-string by aidan
| From: | aidan@php.net | Date: | Sun, 24 May 2009 19:41:24 +0000 |
| Subject: | note 87957 deleted from function.mysql-real-escape-string by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155929@lists.php.net to get a copy of this message | ||
Note Submitter: alan at binarystars dot com
----
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.
<?php
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