So, I found this wonderful function that converts mysql queries to an XML page, and it looks like what I need. The only problem is that it uses mysql, but it is no longer supported, and it turns out that one of the functions is not used in mysqli. Does anyone know an alternative to mysql_field_name?
Here is the function I found
function sqlToXml($queryResult, $rootElementName, $childElementName) { $xmlData = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n"; $xmlData .= "<" . $rootElementName . ">"; while($record = mysql_fetch_object($queryResult)) { $xmlData .= "<" . $childElementName . ">"; for ($i = 0; $i < mysql_num_fields($queryResult); $i++) { $fieldName = mysql_field_name($queryResult, $i); $xmlData .= "<" . $fieldName . ">"; if(!empty($record->$fieldName)) $xmlData .= $record->$fieldName; else $xmlData .= "null"; $xmlData .= "</" . $fieldName . ">"; } $xmlData .= "</" . $childElementName . ">"; } $xmlData .= "</" . $rootElementName . ">"; return $xmlData; }
Given this part
$fieldName = mysql_field_name($queryResult, $i);
thanks
Mike
source share