所以我发现这个很棒的函数将
mysql查询转换为
XML页面,它看起来就像我需要的那样.唯一的问题是它使用MysqL,但不再支持它,并且事实证明使用的函数之一不在MysqLi中.有谁知道MysqL_field_name的替代品?
这是我找到的功能
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; }
有问题的部分是
$fieldName = MysqL_field_name($queryResult,$i);
谢谢
麦克风
有很多方法可以做到,我猜最相似的方法是:
原文链接:https://www.f2er.com/php/135450.html$fieldName = MysqLi_fetch_field_direct($result,$i)->name;
http://www.php.net/manual/en/mysqli-result.fetch-field-direct.php