我想爲我的數據庫選擇最後一行,並將標題爲s1和s2的列回顯到網頁主體,以下是我的代碼。這給出了一個錯誤。無法在php中使用mysqli_result類型的對象作爲數組Mysql
<html>
<body>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mydb2";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT s1, s2 from reading ORDER BY id DESC LIMIT 1";
$row = array();
$row = mysqli_query($conn,$sql);
echo " cup 1". $row["s1"]. "CUP 2". $row["s2"];
?>
</body>
</html>
你跳過了'fetch'部分,查詢執行後,獲取結果 – Ghost