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

标签 php mysql mysqli

假设我有这个变量:

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

根据 php.net 的那个 mysqli_result 对象有几个方法和这些属性:

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

很酷..但是如果我

print_r($my_query_object)

我在对象描述的末尾得到这个属性 [type] => 0

问题 1: 这个属性是什么以及为什么它没有在 mysqli_result 页面中提及?!

问题 2: 如何打印/回显/记录/列出对象的方法和属性 如果我不能同时执行这两项操作(在一个命令中打印属性和方法),至少我怎么能打印一个对象的方法,厌倦了来回到 php.net 只是为了检查对象的解剖结构..

谢谢

最佳答案

这在 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.

要获取对象的属性,可以使用 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();

关于php - mysqli_result 对象中的 'type' 属性代表什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52305140/

相关文章:

PHP mysqli fetch_row - 遍历多条记录

php - mysqli_fetch_assoc()需要参数/调用成员函数bind_param()错误。如何获取并修复实际的mysql错误?

c# - PHP 中的意外行为 - 相同的代码在 C# 和 Python 中给出正确的结果

php - mysqlnd 没有 mysqli_stmt_get_result()

php - mysql_connect 在 XAMPP 中不工作

mysql - 导航最后一页时 Grails 查询分页速度太慢

php - exec ('top' , $output) 返回一个空数组?

c# - 从 C# Windows 应用程序中的 PHP 页面获取 utf8 字符串

PHPExcel 发生超时

php - 如何定位 mysqli 查询返回的特定行