note 73418 added to function.stripslashes
| From: | gregory at nutt dot ca | Date: | Thu, 22 Feb 2007 14:48:25 +0000 |
| Subject: | note 73418 added to function.stripslashes | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-123710@lists.php.net to get a copy of this message | ||
Here is code I use to clean the results from a MySQL query using the stripslashes function.
I do it by passing the sql result and the sql columns to the function strip_slashes_mysql_results.
This way, my data is already clean by the time I want to use it.
function db_query($querystring, $array, $columns)
{
if (!$this->connect_to_mysql())
return 0;
$queryresult = mysql_query($querystring, $this->link)
or die("Invalid query: " . mysql_error());
if(mysql_num_rows($queryresult))
{
$columns = mysql_field_names ($queryresult);
if($array)
{
while($row = mysql_fetch_row($queryresult))
$row_meta[] = $this->strip_slashes_mysql_results($row, $columns);
return $row_meta;
}
else
{
while($row = mysql_fetch_object($queryresult))
$row_meta[] = $this->strip_slashes_mysql_results($row, $columns);
return $row_meta;
}
}
else
return 0;
}
function strip_slashes_mysql_results($result, $columns)
{
foreach($columns as $column)
{
if($this->debug)
printp(sprintf("strip_slashes_mysql_results: %s",strip_slashes_mysql_results));
$result->$column = stripslashes($result->$column);
}
return $result;
}
----
Server IP: 66.207.199.35
Probable Submitter: 142.46.11.201
----
Manual Page -- http://www.php.net/manual/en/function.stripslashes.php
Edit -- https://master.php.net/note/edit/73418
Del: integrated -- https://master.php.net/note/delete/73418/integrated
Del: useless -- https://master.php.net/note/delete/73418/useless
Del: bad code -- https://master.php.net/note/delete/73418/bad+code
Del: spam -- https://master.php.net/note/delete/73418/spam
Del: non-english -- https://master.php.net/note/delete/73418/non-english
Del: in docs -- https://master.php.net/note/delete/73418/in+docs
Del: other reasons-- https://master.php.net/note/delete/73418
Reject -- https://master.php.net/note/reject/73418
Search -- https://master.php.net/manage/user-notes.php