我在 Windows 上使用 wamp 服务器。从我的数据库中获取一点数据时,我的页面严重挂起。它就像一个简单的帖子,有 1 个图像 1 个标题和一些描述,当我触发命令时,它会严重挂起我的页面。这是我的代码的样子。
<?php
//1. Create a connection
$connection= mysql_connect("localhost","root","");
if(!$connection){
die("Database Connection Failed :" . mysql_error());
}
//2 Select a database to use
$db_select = mysql_select_db("gat", $connection);
if (!$db_select) {
die("Database selection failed: " . mysql_error());
}
?>
<html>
<head>
<title>Database Check</title>
</head>
<body>
<?php
//3 perform database query
$result=mysql_query("SELECT * FROM recent_works",$connection);
if (!$result) {
die("Database query failed:" . mysql_error());
}
//4 use returned data
while ($row= mysql_fetch_assoc($result)) {
echo "<div class='work_item'>";
echo "<img src='{$row['image']}' alt=''>";
echo "<h2>{$row['title']}</h2>";
echo "<p>{$row['short_discription']}</p>";
echo "</div>";
}
?>
</body>
</html>
<?php
//5 close connection
mysql_close($connection);
?>