我正试图让我的头脑周围的mysqli,以便我可以更新我的网站,使其更安全。我在数据库中有一篇文章,我试图像使用mysql一样回应它。我在这里看到了关于基本mysqli的负载和大量帖子,但找不到让它工作的方法。所以我道歉,如果我问过一个已被问过的问题,但我到目前为止所得到的主要是我在这里找到的结果。
我收到以下错误:
Fatal error: Cannot use object of type mysqli_result as array in C:\xampp\htdocs\workshop\msqli-test.php on line 20
这是我到目前为止的代码:
<?php
$DBServer = 'localhost';
$DBUser = 'root';
$DBPass = 'pass';
$DBName = 'test_db';
$conn = new mysqli($DBServer, $DBUser, $DBPass, $DBName);
// check connection
if ($conn->connect_error) {
trigger_error('Database connection failed: ' . $conn->connect_error, E_USER_ERROR);
}
$sql='SELECT * FROM articles WHERE title = "Simple Ideas For Your Website Logo."';
$row=$conn->query($sql);
echo "<div class='articlepreviewlayoutreadmore'><a href='".$row['link']."'>Read Full Article</a></div>";
echo "<img src='".$row['images']."' />";
echo "<h3><a href='".$row['link']."'>";
echo $row['title']."</a></h3>";
echo "<h6>Author: ".$row['author']."</h6>";
echo "<h6>Published:".$row['timestamp']."</h6>";
echo "<p>".$row['content']."</p>";
echo "<div class='articlepreviewlayoutreadmore'><a href='".$row['link']."'>Read Full Article</a></div>";
?>
提前感谢您对此的任何帮助,我已经老了,并且日复一日地使用编程语言变得越来越难。
答案 0 :(得分:0)
你错过了一步。执行查询后,您将获得返回的结果对象。然后,您需要使用它来获得结果:
$sql='SELECT * FROM articles WHERE title = "Simple Ideas For Your Website Logo."';
$result = $conn->query($sql);
$row = $result->fetch_assoc();