`<?php
namespace model;
use PDO;
//数据连接,数据查询
class Db
{
//数据库连接
private $dsn;
private $user;
private $password;
private $pdo;
public function connect()
{
try {
$this->pdo = new PDO($this->dsn, $this->user, $this->password);
} catch (PDOException $e) {
die('数据库连接失败,错误信息:' . $e->getMessage());
}
}
public function __construct($dsn = 'mysql:host=localhost;dbname=phpdzy', $user = 'root', $password = 'root')
{
// $this->pdo = new PDO($dsn,$user,$password);
$this->dsn = $dsn;
$this->user = $user;
$this->password = $password;
$this->connect();
}
//获取用户全部信息
public function seleUsers()
{
$sql = 'SELECT * FROM `category`';
$stmt = $this->pdo->prepare($sql);
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
// 查询多条记function select($table,$fields='*',$where='',$order='',$limit='// 创建SQL语句
// 查询多条记录
function select($table ,$where = ‘’, $limit = ‘’, $fields = ‘*’, $order = ‘’)
{
// 创建SQL语句
$sql = ‘SELECT ‘;
if (is_array($fields)) {
foreach ($fields as $field) {
$sql .= $field . ‘, ‘;
}
} else {
$sql .= $fields;
}
$sql = rtrim(trim($sql), ‘,’);
$sql .= ‘ FROM ‘ . $table;
// 查询条件
if (!empty($where)) {
$sql .= ‘ WHERE ‘ . $where;
}
// 排序方式
if (!empty($order)) {
$sql .= ‘ ORDER BY ‘ . $order;
}
// 分页
if (!empty($limit)) {
$sql .= ‘ LIMIT ‘ . $limit;
}
$sql .= ‘;’;
// 创建PDO预处理对象
$stmt = $this->pdo->prepare($sql);
// 执行查询操作
if ($stmt->execute()) {
if ($stmt->rowCount() > 0) {
$stmt->setFetchMode(PDO::FETCH_ASSOC);
return $stmt->fetchAll();
}
}
return ‘查询失败’;
}
// 查询单条记录
function find($table,$fields,$where=''){
$sql = 'SELECT ';
if(is_array($fields)){
foreach ($fields as $field){
$sql .= $field . ', ';
}
}else{
$sql .= $fields;
}
$sql = rtrim(trim($sql),',');
$sql .= ' FROM ' . $table;
if(!empty($where)){
$sql .= ' WHERE ' . $where;
}
$sql .= ' LIMIT 1;';
$stmt = $this->pdo->prepare($sql);
// print_r($stmt);
if($stmt->execute()){
if ($stmt->rowCount()>0){
$stmt->setFetchMode(PDO::FETCH_ASSOC);
return $stmt->fetch();
}
}
return ‘查询失败’;
}
}
//
// $db = new Db();
//print_r($db->seleUsers());
//$data =$db->select(‘users’);
////print_r($data);
//查询多条记录
// echo ‘<pre>‘ .print_r($db->select(‘article’),true);
// 查询单条记录
//echo ‘<pre>‘ .print_r($db->find(‘users’,’*’,’user = “gzg”‘ ),true);
//$data =new Db();
//$data1=$data->find(‘users’,’*’,’user=”gzg”‘);
//print_r($data1);
`
`<?php
namespace ph;
use model\Db;
use view\View1;
require DIR . ‘/Model/model.php’;
require DIR . ‘/View/View.php’;
class indexConter
{
public function article($table,$where,$limit)
{
$art = new Db();
$art1 =$art->select($table,$where,$limit);
// print_r($art1);
$view =new View1;
return $view->getData($art1);
}
public function category($table,$where,$limit)
{
$cat =new Db();
$cat =$cat->select($table,$where,$limit);
$view =new View1;
return $view->getData($cat);
}
}
$index =new indexConter();
//$index =new indexConter();
// $res=$index->article(‘article’);
// print_r($res);
//$art = new Db();
//$art1 =$art->select(‘article’);
//print_r($art1);
//exit();`
`<?php
use ph\indexConter;
require DIR . ‘/head.php’;
require DIR .’./../indexConter.php’;
//$limit1=$index->article(‘article’,’1’);
$limit9=$index->article(‘article’,’cate_id=1’,’9’);
$limit92=$index->article(‘article’,’cate_id=2’,’9’);
// print_r($limit9);
$cat =$index->category(‘category’,’cate_id=1’,’1’);
$cat1 =$index->category(‘category’,’cate_id=2’,’1’);
$pic =$index->article(‘image’,’’,’’);
$pic_con =$index->article(‘image_conten’,’image_id=1’,’2’);
$pic_con_2 =$index->article(‘image_conten’,’image_id=1’,’2,2’);
$phop = $index->article(‘phop’,’’,’’);
$phop_con = $index->article(‘phop_conten’,’phop_id=1’,’4’);
$phop_con_4 = $index->article(‘phop_conten’,’phop_id=1’,’4,4’);
//print_r($phop);
//print_r($phop_con);
//$id=$pic[‘image_id’];
//print_r($id);
//exit;
//print_r($pic_con_2);
//class article1
//{
//
// public function arct1($art1)
// {
//
// foreach ($art1 as $v) {
// // echo $v[‘title’];
// echo ‘<li><span>[新闻]</span><a href=""> ‘;
// echo $v[‘title’];
// echo ‘<br>‘;
// echo ‘</a></li>‘;
// }
//
// }
//
//
//
//}
//echo ‘1110’;
// $data = new article1( );
// print_r($data->arct1($art1));
//print_r($data);
?>
<!--新闻资讯区-->
<div class="news">
<div class="title">
<a>新闻资讯</a>
<a href="">更多</a>
</div>
<div class="content">
<div class="pic">
<a href=""><img src="/phpdzy/static/images/news.jpg" alt="" class="first-img"></a>
<a href=""><img src="/phpdzy/static/images/n-2.jpg" alt=""></a>
<a href=""><img src="/phpdzy/static/images/n-3.jpg" alt=""></a>
<a href="">三星Note10/10+发布 <br> 搭载挖孔前摄</a>
<a href="">小米公布6400万 <br> 和1亿像素手机信息</a>
</div>
<div class="list">
<?php foreach ($cat as $c) : ?>
<!-- mb_substr($row['title'],0,15 ) 取前15个字段 -->
<a href="article_list.php?id=<?php echo $c['cate_id'] ?>"><?php echo mb_substr($c['name'],0,15 )?></a>
<?php endforeach;?>
<ul><?php foreach ($limit9 as $row9) : ?>
<li><span>[新闻]</span><a href="article.php?id=<?php echo $row9['article_id'] ?>"><?php echo $row9['title'] ?></a></li>
<?php endforeach;?>
<!-- <li><span>[新闻]</span><a href="">佳能注册相机无线充电和眼控对焦专利</a></li>-->
<!-- <li><span>[新闻]</span><a href="">Entaniya宣布推出Super 35 PL卡口鱼眼镜头</a></li>-->
<!-- <li><span>[新闻]</span><a href="">轻便灵巧可变形 JOBY入门迷你三脚架套装试用</a></li>-->
<!-- <li><span>[新闻]</span><a href="">乐摄宝Photo Active BP 300 AW背包评测</a></li>-->
<!-- <li><span>[新闻]</span><a href="">佳能注册相机无线充电和眼控对焦专利</a></li>-->
<!-- <li><span>[新闻]</span><a href="">Entaniya宣布推出Super 35 PL卡口鱼眼镜头</a></li>-->
<!-- <li><span>[新闻]</span><a href="">轻便灵巧可变形 JOBY入门迷你三脚架套装试用</a></li>-->
<!-- <li><span>[新闻]</span><a href="">乐摄宝Photo Active BP 300 AW背包评测</a></li>-->
<!-- <li><span>[新闻]</span><a href="">乐摄宝Photo Active BP 300 AW背包评测</a></li>-->
</ul>
</div>
<div class="list">
<?php foreach ($cat1 as $row1) : ?>
<!-- <a href="">性价比广角 腾龙17-28F2.8评测</a>-->
<a href="article_list.php?id=<?php echo $row1['cate_id'] ?>"><?php echo mb_substr($row1['name'],0,15) ?></a>
<?php endforeach;?>
<ul>
<?php foreach ($limit92 as $row9) : ?>
<li><span>[新闻]</span><a href="article.php?id=<?php echo $row9['article_id'] ?>"><?php echo $row9['title'] ?></a>
<?php endforeach; ?>
<!-- <li><span>[新闻]</span><a href="">佳能注册相机无线充电和眼控对焦专利</a></li>-->
<!-- <li><span>[新闻]</span><a href="">Entaniya宣布推出Super 35 PL卡口鱼眼镜头</a></li>-->
<!-- <li><span>[新闻]</span><a href="">轻便灵巧可变形 JOBY入门迷你三脚架套装试用</a></li>-->
<!-- <li><span>[新闻]</span><a href="">乐摄宝Photo Active BP 300 AW背包评测</a></li>-->
<!-- <li><span>[新闻]</span><a href="">佳能注册相机无线充电和眼控对焦专利</a></li>-->
<!-- <li><span>[新闻]</span><a href="">Entaniya宣布推出Super 35 PL卡口鱼眼镜头</a></li>-->
<!-- <li><span>[新闻]</span><a href="">轻便灵巧可变形 JOBY入门迷你三脚架套装试用</a></li>-->
<!-- <li><span>[新闻]</span><a href="">乐摄宝Photo Active BP 300 AW背包评测</a></li>-->
<!-- <li><span>[新闻]</span><a href="">乐摄宝Photo Active BP 300 AW背包评测</a></li>-->
</ul>
</div>
</div>
</div>
<!--图片专区-->
<div class="title">
<span>图片专区</span>
</div>
<div class="picture">
<?php foreach ($pic as $p) :?>
<div>
<div>
<a href="image.php?id=<?php echo $p['image_id'] ?>"><?php echo $p[‘name’] ?></a>
<span>纵观摄影艺术</span>
</div>
<?php foreach ($pic_con as $pi ): ?>
<a href="image-content.php?id=<?php echo $pi['image_con_id'] ?> "><img src="<?php echo $pi['dz'] ?>" alt="" width="162" height="122"></a>
<?php endforeach; ?>
<?php foreach ($pic_con as $pi ): ?>
<a href="image-content.php?id=<?php echo $pi['image_con_id'] ?>"><span><?php echo $pi['title'] ?></span></a>
<?php endforeach; ?>
<?php foreach ($pic_con_2 as $pi ): ?>
<a href="image-content.php?id=<?php echo $pi['image_con_id'] ?>"><img src="<?php echo $pi['dz'] ?>" alt="" width="162" height="122"></a>
<?php endforeach; ?>
<?php foreach ($pic_con_2 as $pi ): ?>
<a href="image-content.php?id=<?php echo $pi['image_con_id'] ?>"><span><?php echo $pi['title'] ?></span></a>
<?php endforeach; ?>
<!-- <a href=""><img src="/phpdzy/static/images/img1.jpg" alt="" width="162" height="122"></a>-->
<!-- <a href=""><img src="/phpdzy/static/images/img2.jpg" alt="" width="162" height="122"></a>-->
<!-- <a href=""><span>阴沉夏日的柔美身姿 复古少女的藕荷色心情</span></a>-->
<!-- <a href=""><span>阴沉夏日的柔美身姿 复古少女的藕荷色心情</span></a>-->
<!-- <a href=""><img src="/phpdzy/static/images/img3.jpg" alt="" width="162" height="122"></a>-->
<!-- <a href=""><img src="/phpdzy/static/images/img4.jpg" alt="" width="162" height="122"></a>-->
<!-- <a href=""><span>阴沉夏日的柔美身姿 复古少女的藕荷色心情</span></a>-->
<!-- <a href=""><span>阴沉夏日的柔美身姿 复古少女的藕荷色心情</span></a>-->
</div>
<?php endforeach; ?>
<!-- <div>-->
<!-- <div>-->
<!-- <a href="">美女</a>-->
<!-- <span>纵观摄影艺术</span>-->
<!-- </div>-->
<!-- <a href=""><img src="/phpdzy/static/images/img5.jpg" alt="" width="162" height="122"></a>-->
<!-- <a href=""><img src="/phpdzy/static/images/img6.jpg" alt="" width="162" height="122"></a>-->
<!-- <a href=""><span>阴沉夏日的柔美身姿 复古少女的藕荷色心情</span></a>-->
<!-- <a href=""><span>阴沉夏日的柔美身姿 复古少女的藕荷色心情</span></a>-->
<!-- <a href=""><img src="/phpdzy/static/images/img7.jpg" alt="" width="162" height="122"></a>-->
<!-- <a href=""><img src="/phpdzy/static/images/img8.jpg" alt="" width="162" height="122"></a>-->
<!-- <a href=""><span>阴沉夏日的柔美身姿 复古少女的藕荷色心情</span></a>-->
<!-- <a href=""><span>阴沉夏日的柔美身姿 复古少女的藕荷色心情</span></a>-->
<!-- </div>-->
<!---->
<!-- <div>-->
<!-- <div>-->
<!-- <a href="">美女</a>-->
<!-- <span>纵观摄影艺术</span>-->
<!-- </div>-->
<!-- <a href=""><img src="/phpdzy/static/images/img1.jpg" alt="" width="162" height="122"></a>-->
<!-- <a href=""><img src="/phpdzy/static/images/img2.jpg" alt="" width="162" height="122"></a>-->
<!-- <a href=""><span>阴沉夏日的柔美身姿 复古少女的藕荷色心情</span></a>-->
<!-- <a href=""><span>阴沉夏日的柔美身姿 复古少女的藕荷色心情</span></a>-->
<!-- <a href=""><img src="/phpdzy/static/images/img3.jpg" alt="" width="162" height="122"></a>-->
<!-- <a href=""><img src="/phpdzy/static/images/img4.jpg" alt="" width="162" height="122"></a>-->
<!-- <a href=""><span>阴沉夏日的柔美身姿 复古少女的藕荷色心情</span></a>-->
<!-- <a href=""><span>阴沉夏日的柔美身姿 复古少女的藕荷色心情</span></a>-->
<!-- </div>-->
</div>
<!--二手交易专区-->
<div class="title">
<span>二手交易</span>
</div>
<div class="second-hand">
<div>
<a href="">抢好货</a>
<span>0低价, 便捷,安全,快速</span>
</div>
<div>
<span>热门分类</span>
<?php foreach ($phop as $p) : ?>
<a href="shop.php?id=<?php echo $p['phop_id'] ?>"><?php echo $p[‘name’] ?></a>
<?php endforeach; ?>
<!-- <a href="">美女写真</a>-->
<!-- <a href="">日本美女</a>-->
<!-- <a href="">美国美女</a>-->
<!-- <a href="">国内美女</a>-->
<!-- <a href="">AV美女</a>-->
</div>
<?php foreach ($phop_con as $ph) : ?>
<a href="shop-content.php?id=<?php echo $ph['id'] ?>"><img src="<?php echo $ph['tp'] ?>" alt="" width="176" height="120"></a>
<?php endforeach; ?>
<!-- <a href=""><img src="/phpdzy/static/images/shop/shop1.jpg" alt="" width="176" height="120"></a>-->
<!-- <a href=""><img src="/phpdzy/static/images/shop/shop2.jpg" alt="" width="176" height="120"></a>-->
<!-- <a href=""><img src="/phpdzy/static/images/shop/shop3.jpg" alt="" width="176" height="120"></a>-->
<!-- <a href=""><img src="/phpdzy/static/images/shop/shop4.jpg" alt="" width="176" height="120"></a>-->
<?php foreach ($phop_con as $ph) : ?>
<div class="detail">
<a href="shop-content.php?id=<?php echo $ph['id'] ?>"><?php echo $ph[‘title’] ?></a>
<div>
<a href="shop-content.php?id=<?php echo $ph['id'] ?>">
<span>¥ <?php echo $ph[‘amnt’]?></span>
<span>美女</span>
</a>
</div>
</div>
<?php endforeach; ?>
<!-- <div class="detail">-->
<!-- <a href="">美女性感写真海报墙面贴画艺术装画</a>-->
<!-- <div>-->
<!-- <a href="">-->
<!-- <span>¥ 333</span>-->
<!-- <span>美女</span>-->
<!-- </a>-->
<!-- </div>-->
<!-- </div>-->
<!-- <div class="detail">-->
<!-- <a href="">美女性感写真海饰画酒吧卧室贴画图画</a>-->
<!-- <div>-->
<!-- <a href="">-->
<!-- <span>¥ 333</span>-->
<!-- <span>美女</span>-->
<!-- </a>-->
<!-- </div>-->
<!-- </div>-->
<!-- <div class="detail">-->
<!-- <a href="">美女性感写真海饰画酒吧卧室贴画图画</a>-->
<!-- <div>-->
<!-- <a href="">-->
<!-- <span>¥ 333</span>-->
<!-- <span>美女</span>-->
<!-- </a>-->
<!-- </div>-->
<!-- </div>-->
<?php foreach ($phop_con_4 as $ph) : ?>
<a href="shop-content.php?id=<?php echo $ph['id'] ?>"><img src="<?php echo $ph['tp'] ?>" alt="" width="176" height="120"></a>
<?php endforeach; ?>
<!-- <a href=""><img src="/phpdzy/static/images/shop/shop5.jpg" alt="" width="176" height="120"></a>-->
<!-- <a href=""><img src="/phpdzy/static/images/shop/shop6.jpg" alt="" width="176" height="120"></a>-->
<!-- <a href=""><img src="/phpdzy/static/images/shop/shop7.jpg" alt="" width="176" height="120"></a>-->
<!-- <a href=""><img src="/phpdzy/static/images/shop/shop8.jpg" alt="" width="176" height="120"></a>-->
<?php foreach ($phop_con_4 as $ph) : ?>
<div class="detail">
<a href="shop-content.php?id=<?php echo $ph['id'] ?>"><?php echo $ph[‘title’] ?></a>
<div>
<a href="shop-content.php?id=<?php echo $ph['id'] ?>">
<span>¥ <?php echo $ph[‘amnt’]?></span>
<span>美女</span>
</a>
</div>
</div>
<?php endforeach; ?>
<!-- <div class="detail">-->
<!-- <a href="">美女性感写真海报墙艺术装饰画贴画图画</a><br>-->
<!-- <div>-->
<!-- <a href="">-->
<!-- <span>¥ 333</span>-->
<!-- <span>美女</span>-->
<!-- </a>-->
<!-- </div>-->
<!-- </div>-->
<!-- <div class="detail">-->
<!-- <a href="">美女性感写真海报墙面贴画艺术装画</a>-->
<!-- <div>-->
<!-- <a href="">-->
<!-- <span>¥ 333</span>-->
<!-- <span>美女</span>-->
<!-- </a>-->
<!-- </div>-->
<!-- </div>-->
<!-- <div class="detail">-->
<!-- <a href="">美女性感写真海饰画酒吧卧室贴画图画</a>-->
<!-- <div>-->
<!-- <a href="">-->
<!-- <span>¥ 333</span>-->
<!-- <span>美女</span>-->
<!-- </a>-->
<!-- </div>-->
<!-- </div>-->
<!-- <div class="detail">-->
<!-- <a href="">美女性感写真海饰画酒吧卧室贴画图画</a>-->
<!-- <div>-->
<!-- <a href="">-->
<!-- <span>¥ 333</span>-->
<!-- <span>美女</span>-->
<!-- </a>-->
<!-- </div>-->
<!-- </div>-->
<div>
<a href=""><img src="/phpdzy/static/images/ad/1.png" alt="" width="180" height="112"></a>
<a href=""><img src="/phpdzy/static/images/ad/2.png" alt="" width="180" height="112"></a>
<a href=""><img src="/phpdzy/static/images/ad/3.png" alt="" width="180" height="112"></a>
<a href=""><img src="/phpdzy/static/images/ad/4.png" alt="" width="180" height="112"></a>
<a href=""><img src="/phpdzy/static/images/ad/image.png" alt="" width="393" height="56"></a>
<a href=""><img src="/phpdzy/static/images/ad/ad2.jpg" alt="" width="393" height="56"></a>
</div>
</div>
<!--合作网站-->
<div class="title" style="background:#fff">
<span>合作网站</span>
</div>
<div class="my-links">
<a href="https://www.php.cn">php中文网</a>
<a href="https://www.html.cn">html中文网</a>
<a href="https://www.py.cn">python中文网</a>
<a href="https://www.php.cn">php中文网</a>
<a href="https://www.html.cn">html中文网</a>
<a href="https://www.py.cn">python中文网</a>
<a href="https://www.php.cn">php中文网</a>
<a href="https://www.html.cn">html中文网</a>
<a href="https://www.py.cn">python中文网</a>
<a href="https://www.php.cn">php中文网</a>
<a href="https://www.html.cn">html中文网</a>
<a href="https://www.py.cn">python中文网</a>
<a href="https://www.py.cn">python中文网</a>
<a href="https://www.php.cn">php中文网</a>
<a href="https://www.html.cn">html中文网</a>
<a href="https://www.py.cn">python中文网</a>
<a href="https://www.php.cn">php中文网</a>
<a href="https://www.html.cn">html中文网</a>
<a href="https://www.py.cn">python中文网</a>
<a href="https://www.php.cn">php中文网</a>
<a href="https://www.html.cn">html中文网</a>
<a href="https://www.py.cn">python中文网</a>
<a href="https://www.php.cn">php中文网</a>
<a href="https://www.html.cn">html中文网</a>
<a href="https://www.py.cn">python中文网</a>
<a href="https://www.py.cn">python中文网</a>
</div>
<?php
require DIR . ‘/foot.php’;`
` <h3>推荐阅读</h3>
<?php foreach ($tj_4_1 as $tj) : ?>
<a href="article.php?id=<?php echo $tj['article_id'] ?>"><img src="<?php echo $tj['image'] ?>" alt="" width="195" height="130"></a>
<?php endforeach; ?>
<?php foreach ($tj_4_1 as $ti) : ?>
<a href="article.php?id=<?php echo $tj['article_id'] ?>"><?php echo $ti['title'] ?></a>
<?php endforeach; ?>
<?php foreach ($tj_4_2 as $tj) : ?>
<a href="article.php?id=<?php echo $tj['article_id']?>"><img src="<?php echo $tj['image'] ?>" alt="" width="195" height="130"></a>
<?php endforeach; ?>
<?php foreach ($tj_4_2 as $ti) : ?>
<a href="article.php?id=<?php echo $tj['article_id'] ?>"><?php echo $ti['title'] ?></a>
<?php endforeach; ?>`
<article>
<h1><?php echo $res['title'] ?></h1>
<div>
<span>发布时间:<?php echo $res['fb_date'] ?></span>
<span>来源:<?php echo $res['soure'] ?></span>
<span>阅读量:<?php echo $res['ydl'] ?></span>
<span>评论数:<?php echo $res['pls']?></span>
</div>
<div>
<?php echo $res['detail'] ?>
</div>
</article>
通过近一周的作业,理解了类的调用,熟悉了mvc的结构,熟悉了mysql数据库的操作。