I've managed to reduce the problem down to the following which I'm at a loss to explain:
- Code: Select all
$sql = "SELECT text ";
$sql .= "FROM t_text ";
$sql .= "WHERE name = '$name' ";
$sql .= "AND `site_id` = {$opus['site_id']} ";
$text_result = db_query($sql, __LINE__, __FILE__);
$return1 = mysql_result($text_result, 0, NULL);
print('return1 = ' . $return1 . "<br/>\n");
function mysql_safe_result_local($result, $row = NULL, $field = NULL)
{
$value = mysql_result($result, $row, $field);
$value_safe = htmlspecialchars($value);
return $value_safe;
}
$return2 = mysql_safe_result_local($text_result, 0);
print('return2 = ' . $return2 . "<br/>\n");
function mysql_safe_result_local2($result, $row = NULL)
{
$value = mysql_result($result, $row);
$value_safe = htmlspecialchars($value);
return $value_safe;
}
$return3 = mysql_safe_result_local2($text_result, 0);
print('return3 = ' . $return3 . "<br/>\n");
$return4 = htmlspecialchars(mysql_result($text_result, 0, NULL));
print('return4 = ' . $return4 . "<br/>\n");
This gives me the following result (when 'test test' is the string stored in the database):
return1 = test test
return2 = !���!����
return3 = test test
return4 = test test
Where $return2 looks like nonsense. This only seems to happen when the function is used, not when the equivalent processing happens in line. Within the function, the $field variable needs to be NULL to see the problem. Outside of the function this has no effect in producing the problem.
Can anyone suggest what is going on or what I should do by way of further diagnosis?
Many thanks!