当我对我的数据库进行查询时,结果如下:
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();
当然我不想获得它,我想得到表中包含的行,我的代码有什么问题?
答案 0 :(得分:1)
嗯,您需要首先获取结果,为此,您需要使用->fetch_assoc()
或->fetch_array()
:
// you need to loop it if you're expecting multiple rows
while($row = $result->fetch_assoc()) {
echo $row['column_name'];
}
价:
答案 1 :(得分:0)
你必须做
$row = $result->fetch_assoc();