# 1.新建data_v3/v1/index_1.php文件
~~~
<?php
/**
* Email:y7wanghui@gmail.com
* Date: 2020/11/2 0002
*/
// 计算出数据库的路径,以便SQLite / PDO可以连接
$root = __DIR__;
$database = $root . '/../data/data.sqlite';
$dsn = 'sqlite:' . $database;
// 计算出数据库的路径,以便SQLite / PDO可以连接
$pdo = new PDO($dsn);
$stmt = $pdo->query(
'SELECT
title, created_at, body
FROM
post
ORDER BY
created_at DESC'
);
if ($stmt === false)
{
throw new Exception('运行此查询时出现问题');
}
?>
<!DOCTYPE html>
<html>
<head>
<title>我的博客</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>
<body>
<h1>标题</h1>
<?php while ($row = $stmt->fetch(PDO::FETCH_ASSOC)): ?>
<h2>
<?php echo htmlspecialchars($row['title'], ENT_HTML5, 'UTF-8') ?>
</h2>
<div>
<?php echo $row['created_at'] ?>
</div>
<p>
<?php echo htmlspecialchars($row['body'], ENT_HTML5, 'UTF-8') ?>
</p>
<p>
<a href="#">Read more...</a>
</p>
<?php endwhile ?>
</body>
</html>
~~~
# 2.重写index_1.php为index.php 使得 Read more...可点击
~~~
修改<a href="#">Read more...</a>
为<a href="view-post.php?post_id=<?php echo $row['id']?>">Read more...</a>
我们只需要跳转并传参id到view-post.php即可
~~~
.