note 87957 modified in function.mysql-real-escape-string by danbrown
| From: | danbrown@php.net | Date: | Fri, 02 Jan 2009 18:29:52 +0000 |
| Subject: | note 87957 modified in function.mysql-real-escape-string by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-148757@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.
<?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
--was--
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
http://php.net/manual/en/function.mysql-real-escape-string.php