本文介紹了mysqli 中 mysql_field_name 的替代方案的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
所以我發現了這個將mysql查詢轉換為XML頁面的很棒的函數,它看起來正是我需要的.唯一的問題是它使用了 mysql,但不再受支持,而且結果使用的函數之一不在 mysqli 中.有誰知道 mysql_field_name 的替代方法?
So I found this great function that converts mysql queries into a XML page, and it looks like exactly what I need. The only problem is that it uses mysql, but thats not supported anymore, and it turns out one of the functions used isn't in mysqli. Does anyone know of an alternative to mysql_field_name?
這是我找到的函數
function sqlToXml($queryResult, $rootElementName, $childElementName)
{
$xmlData = "<?xml version="1.0" encoding="ISO-8859-1" ?>
";
$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);
謝謝
邁克
推薦答案
有很多方法可以做到,我猜最相似的是:
There are many ways to do it, I guess the most similar would be:
$fieldName = mysqli_fetch_field_direct($result, $i)->name;
http://www.php.net/手冊/en/mysqli-result.fetch-field-direct.php
這篇關于mysqli 中 mysql_field_name 的替代方案的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!