在我的代码中,我尝试了mysqli_fetch_field,mysqli_fetch_fields和mysqli_fetch_field_direct,但它们似乎都没有工作。这是我的代码:
// Fetch Record from Database
$output = "";
$table = "excel"; // Enter Your Table Name
$sql = mysqli_query($connection, "select * from $table");
$columns_total = mysqli_num_fields($sql);
// Get The Field Name
for ($i = 0; $i < $columns_total; $i++) {
$heading = mysql_field_name($sql, $i);
$output .= '"'.$heading.'",';
}
$output .="\n";
运行此代码的错误是: mysql_field_name()期望参数1为资源
尝试mysqli_fetch_field_direct会出现此错误: 可捕获的致命错误:类stdClass的对象无法转换为
中的字符串有什么想法吗?谢谢!
答案 0 :(得分:0)
在代码中使用mysqli_fetch_field_direct代替mysql_field_name ...请参阅下面的示例
// Fetch Record from Database
$output = "";
$table = "excel"; // Enter Your Table Name
$sql = mysqli_query($connection, "select * from $table");
$columns_total = mysqli_num_fields($sql);
// Get The Field Name
for ($i = 0; $i < $columns_total; $i++) {
$heading = mysqli_fetch_field_direct($sql, $i);
$output .= '"'.$heading.'",';
}
$output .="\n";