Php mysqli查询返回结构而不是数据

Php mysqli查询返回结构而不是数据,php,mysql,select,mysqli,Php,Mysql,Select,Mysqli,当我对数据库进行查询时,结果如下: mysqli_result Object ( [current_field] => 0 [field_count] => 3 [lengths] => [num_rows] => 3 [type] => 0 ) 这是我正在使用的代码: $servername = "localhost"; $username = "root"; $password = ""; // Create con

当我对数据库进行查询时,结果如下:

mysqli_result Object
(
    [current_field] => 0
    [field_count] => 3
    [lengths] => 
    [num_rows] => 3
    [type] => 0
)
这是我正在使用的代码:

$servername = "localhost";
$username = "root";
$password = "";

// Create connection
$conn = new mysqli($servername, $username, $password, 'melona');

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT * FROM votacion";

$result = $conn->query($sql);

echo "<pre>";
print_r($result);
echo "</pre>";

die();
$servername=“localhost”;
$username=“root”;
$password=“”;
//创建连接
$conn=newmysqli($servername,$username,$password,'melona');
//检查连接
如果($conn->connect\u错误){
die(“连接失败:”.$conn->connect\U错误);
} 
$sql=“从votacion选择*”;
$result=$conn->query($sql);
回声“;
打印(结果);
回声“;
模具();

当然,我不想得到这些,我想得到表中包含的行,我的代码怎么了?

好吧,你需要先把结果取出来,要做到这一点,你需要使用
->fetch\u assoc()
->fetch\u array()

参考:

你必须这样做


查询返回一个结果集,然后您可以在何时、何地以及如何取回该结果集(作为assoc数组、作为对象、作为数字索引数组…),这就是它的工作方式,也是它一直以来的工作方式。。。另外:不要死,但要关闭连接,完成后释放资源。这里不需要,但这是一个很好的习惯谢谢,我也应用了你的建议。太好了,我用while($row=$result->fetch_assoc())$array[]=$row;获得一个好的阵列。@Mariano我很高兴这有帮助
// you need to loop it if you're expecting multiple rows
while($row = $result->fetch_assoc()) {
    echo $row['column_name'];
}
$row = $result->fetch_assoc();