简体   繁体   English

mysqli_result对象中的'type'属性代表什么?

[英]What does the 'type' property in the mysqli_result object represent?

let's say I have this variable: 假设我有这个变量:

$my_query_object = $previous_connection->query($my_query);

that mysqli_result object according to php.net has several methods AND these properties: 根据php.net的mysqli_result对象具有几种方法以及这些属性:

int $current_field ;
int $field_count;
array $lengths;
int $num_rows; 

cool.. but if I 酷..但如果我

print_r($my_query_object)

I get this property [type] => 0 at the end of the object description 我在对象描述的末尾得到了此属性[type] => 0

Question 1: what is this property and why it wasn't mentioned in the mysqli_result page?! 问题1:此属性是什么,为什么在mysqli_result页面中未提及?

Question 2: how can I print/echo/log/list the METHODS and PROPERTIES of an object and if I can't do both together (print properties and methods in one command) at least how can I print the methods of an object, got tired of going back and forth to php.net just to check the object's anatomy.. 问题2:如何打印/回显/记录/列出对象的方法和属性,并且如果不能同时执行(在一个命令中打印属性和方法),至少如何打印对象的方法,厌倦了来回php.net只是为了检查对象的解剖结构。

thanks 谢谢

This is best explained in the docs for fetch-all : 最好在fetch-all文档中对此进行解释:

resulttype

This optional parameter is a constant indicating what type of array should be produced from the current row data. 此可选参数是一个常量,指示应从当前行数据中生成哪种类型的数组。 The possible values for this parameter are the constants MYSQLI_ASSOC , MYSQLI_NUM , or MYSQLI_BOTH . 此参数的可能值为常数MYSQLI_ASSOCMYSQLI_NUMMYSQLI_BOTH

To get the properties of an object, you can use get_object_vars() : 要获取对象的属性,可以使用get_object_vars()

 class foo { private $a; public $b = 1; public $c; private $d; static $e; public function test() { var_dump(get_object_vars($this)); } } $test = new foo; var_dump(get_object_vars($test)); $test->test(); 

Okay, after a bit of research I found that 好吧,经过一番研究,我发现

[type] => 0 represents MYSQLI_STORE_RESULT constant [type] => 0代表MYSQLI_STORE_RESULT常数
[type] => 1 represents MYSQLI_USE_RESULT constant [type] => 1代表MYSQLI_USE_RESULT常数
for more information about the behaviour of these constants check this answer . 有关这些常量的行为的更多信息,请检查此答案

In contrast to Obsidian Age 's answer the number doesn't represent the type of the array and whether it's associative or numeric but the resultmode of the query() method Obsidian Age的答案相反,数字不代表数组的类型,也不代表数组是关联的还是数字的,而是query()方法的resultmode

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM