Jump to content

Cleaning mysql results


Perfidus

Recommended Posts

Hi there again, before introducing my data in mysql I'm using mysql_real_escape_string().

Afterwords, when I want my data back, I'm applying to every result this two functions:

utf8_encode(stripslashes($row['result1']))

Is there a way to apply this double function somewhere before so I don't need to write it down again and again for every result?

Somewhere in the query function...

 

function getData($ref)
{
$sql="SELECT * FROM thetable WHERE ref= '$ref";
$rs = mysql_query($sql) or die(mysql_error() . "<br>$sql");
$row = mysql_fetch_array($rs);
return $row;	
}

Link to comment
https://forums.phpfreaks.com/topic/150893-cleaning-mysql-results/
Share on other sites

And again I'm answering myself...

Please, if someone has a suggestion, tell me, I have tried this and it works like a charm.

function getData($ref)
{
$sql="SELECT * FROM thetable WHERE ref= '$ref";
$rs = mysql_query($sql) or die(mysql_error() . "<br>$sql");
$row = mysql_fetch_array($rs);
foreach ($row as &$value) {
    $value = utf8_encode(stripslashes($value));
}
unset($value); // 
return $row;	
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.