我有以下代码:
//preparing statement, executing and so on is omitted...
//$this->cur_query_stmt is object returned by prepare() function
var_dump($this->cur_query_stmt);
foreach($this->cur_query_stmt as $k=>$v){
var_dump($k);
var_dump($v);
}
此代码的输出:
object(mysqli_stmt)#6 (9) {
["affected_rows"]=>
int(1)
["insert_id"]=>
int(7)
["num_rows"]=>
int(0)
["param_count"]=>
int(1)
["field_count"]=>
int(0)
["errno"]=>
int(0)
["error"]=>
string(0) ""
["sqlstate"]=>
string(5) "00000"
["id"]=>
int(2)
}
string(13) "affected_rows"
NULL
string(9) "insert_id"
NULL
string(8) "num_rows"
NULL
string(11) "param_count"
NULL
string(11) "field_count"
NULL
string(5) "errno"
NULL
string(5) "error"
NULL
string(8) "sqlstate"
NULL
string(2) "id"
NULL
谁能解释为什么所有值都返回为NULL?
我可以通过调用 $this->cur_query_stmt->$this->affected_rows 来获取它们,但是当尝试在 foreach 或 get_object_vars 函数中获取它们时,我得到的是 NULL。我很困惑,请帮助!