alternative to mysql_field_name in mysqli(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 的替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:mysqli 中 mysql_field_name 的替代方案


- 没有作曲家的 PSR4 自动加载 2022-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- Laravel 仓库 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01