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:
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
Question 1: what is this property and why it wasn't mentioned in the mysqli_result
page?!
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..
thanks
This is best explained in the docs for 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
, orMYSQLI_BOTH
.
To get the properties of an object, you can use 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] => 1
represents MYSQLI_USE_RESULT
constant
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.