为什么在本例中获取结果返回对象?
function db_connect() {
$db_host='localhost';
$db_name='contact_manager';
$db_user='root';
$db_pass='';
$connection = new mysqli($db_host, $db_user, $db_pass, $db_name);
return $connection;
}
$connection = db_connect();
$query = $connection->prepare("SELECT * FROM users");
$query->execute();
$op = $query->get_result();
var_dump($op);
这是vardump:
object(mysqli_result)#3 (5) {
["current_field"]=> int(0)
["field_count"]=> int(4)
["lengths"]=> NULL
["num_rows"]=> int(24)
["type"]=> int(0) }
1条答案
按热度按时间anhgbhbe1#
根据官方文件(此处),
get_result()
为成功的选择查询返回结果集。接下来必须从结果集中提取数据,例如$result->fetch_assoc()
: