mysql_field_name 到新的 mysqli

2021-12-25 00:00:00 php mysqli

我有办法获取表列的名称.它工作正常,但现在我想更新到新的 mysqli ?(我尝试了 mysqli_fetch_field 但我不知道如何应用到这种情况下,我不确定它是否是 wright 选项)

I have a way to get the name of the columns of a table. It works fine but now I want to update to the new mysqli ? (I tried the mysqli_fetch_field but I don't know how to apply to this case and I am not sure if it is the wright option)

如何用 mysqli 做同样的事情?:

How to do the same with mysqli ? :

$sql = "SELECT * from myTable";
$result = mysql_query($sql,$con);
$id = mysql_field_name($result, 0);
$a = mysql_field_name($result, 1);

echo $id;
echo $a;

推荐答案

我不确定是否有更好的方法来做到这一点,但我检查了这是否可以仅获取列的名称并且是新的mysqli:

I'm not sure if there is a better way to do that, but I checked that this works to get just the name of the columns and is the new mysqli :

$result = mysqli_query($con, 'SELECT * FROM myTable');
while ($property = mysqli_fetch_field($result)) {
    echo $property->name;
}

相关文章