整理好素材及開完資料表後,接著我們會製作DB類別檔,把會用到的一些功能都封裝在DB類別中。
建立題組專用共用函式檔
api/db.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| session_start(); date_default_timezone_set("Asia/Taipei");
function dd($array){ echo "<pre>"; print_r($array); echo "</pre>"; }
function to($url){ header("location:".$url); }
function q($sql){ $pdo=new PDO("mysql:host=localhost;charset=utf8;dbname={your db name}",'root',''); return $pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC); }
$Poster=new DB('poster'); $Movie=new DB('movie'); $Order=new DB('ord');
|
接著將這個檔案引入到 index.php
及 back.php
中:
/index.php 、 /back.php
1 2 3 4
| <?php include_once "./api/db.php"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
|