Blogger Information
Blog 11
fans 0
comment 1
visits 8247
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
操作pdo实现网站的动态实现
梦惊禅的博客
Original
732 people have browsed it

因为文件较多,使用 外部链接 http://www.mengjingchan.xin/movie/

附主要pdo代码

1、PDO类文件

class Pd

{

    public $dsn = 'mysql:dbname=liuyan;host=127.0.0.1';

    public $user = 'liuyan';

    public $password = 'liuyan';

    public $dbh;

    public function __construct(){

        try {

            $this->dbh = new PDO($this->dsn, $this->user, $this->password);

            date_default_timezone_set("PRC");

        } catch (PDOException $e) {

            echo 'Connection failed: ' . $e->getMessage();

            exit();

        }

    }

}

2、查询信息文件

require_once ("Pd.php");

$pdo = new Pd();

$db = $pdo->dbh;

$sql = "select * from category";

$stmt = $db->prepare($sql);

if($stmt->execute()){

    $nav = $stmt->fetchAll(PDO::FETCH_ASSOC);

}else{

    echo "查询cate失败";

}


$sql = "select * from movies";

$stmt = $db->prepare($sql);

if($stmt->execute()){

    $movies = $stmt->fetchAll(PDO::FETCH_ASSOC);

}else{

    echo "movies查询失败";

}


Correction status:qualified

Teacher's comments:完成的不错。类还没学呢,就会写了
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post