因为文件较多,使用 外部链接 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查询失败";
}