Mysql_field_name alternative in mysqli

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)) { /* Create the first child element */ $xmlData .= "<" . $childElementName . ">"; for ($i = 0; $i < mysql_num_fields($queryResult); $i++) { $fieldName = mysql_field_name($queryResult, $i); /* The child will take the name of the table column */ $xmlData .= "<" . $fieldName . ">"; /* We set empty columns with NULL, or you could set it to '0' or a blank. */ 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

+6
source share
1 answer

There are many ways to do this, I think the most similar would be:

 $fieldName = mysqli_fetch_field_direct($result, $i)->name; 

http://www.php.net/manual/en/mysqli-result.fetch-field-direct.php

+18
source

Source: https://habr.com/ru/post/954376/


All Articles