php MYSQLI_NUM 是什么意思和做什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1684993/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:30:14  来源:igfitidea点击:

What does MYSQLI_NUM mean and do?

phpmysql

提问by aBc

I just wanted a little bit of information on MYSQLI_NUM. And is it part of PHP or MySQL.

我只是想要一些关于 MYSQLI_NUM 的信息。它是 PHP 还是 MySQL 的一部分。

回答by Travis

MYSQLI_NUM is a constant in PHP associated with a mysqli_result. If you're using mysqli to retrieve information from the database, MYSQLI_NUM can be used to specify the return format of the data. Specifically, when using the fetch_array function, MYSQLI_NUM specifies that the return array should use numeric keys for the array, instead of creating an associative array. Assuming you have two fields in your database table, "first_field_name" and "second_field_name", with the content "first_field_content" and "second_field_content"...

MYSQLI_NUM 是 PHP 中与 mysqli_result 关联的常量。如果您使用 mysqli 从数据库中检索信息,则 MYSQLI_NUM 可用于指定数据的返回格式。具体来说,在使用 fetch_array 函数时,MYSQLI_NUM 指定返回数组应该使用数字键作为数组,而不是创建关联数组。假设您的数据库表中有两个字段“first_field_name”和“second_field_name”,内容为“first_field_content”和“second_field_content”...

$result->fetch_array(MYSQLI_NUM);

fetches each row of the result like this:

像这样获取结果的每一行:

array(
    0 => "first_field_content",
    1 => "second_field_content"
);

Alternatively...

或者...

$result->fetch_array(MYSQLI_ASSOC);

fetches an array like this:

获取这样的数组:

array(
    "first_field_name" => "first_field_content",
    "second_field_name" => "second_field_content"
);

Using the constant MYSQLI_BOTH will fetch both.

使用常量 MYSQLI_BOTH 将获取两者。

回答by HorusKol

It is a PHP constant used in mysqli_fetch_array()

它是mysqli_fetch_array() 中使用的 PHP 常量

This tells the function that you want it to return a record from your results as a numerically indexed array instead of an associative one (MYSQLI_ASSOC) or both (MYSQLI_BOTH).

这告诉函数您希望它从结果中返回一个记录作为数字索引数组而不是关联数组 (MYSQLI_ASSOC) 或两者 (MYSQLI_BOTH)。

Alternatively, you can just use mysqli_fetch_row() to do the same thing.

或者,您可以只使用 mysqli_fetch_row() 来做同样的事情。

回答by Mathew

Google is your friend! ;) MYSQLI_NUM is a PHP constant used by the mysqli database extension;

谷歌是你的朋友!;) MYSQLI_NUM 是 mysqli 数据库扩展使用的 PHP 常量;

http://uk3.php.net/manual/en/mysqli.constants.php

http://uk3.php.net/manual/en/mysqli.constants.php