class WebApp public db public catalog public filter public goods publi

 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
class WebApp
{
public $db;
public $catalog;
public $filter;
public $goods;
public $card;
public $cart;
public function __construct($host, $dbname, $user, $pass)
{
$this->db=new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
$this->db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$this->db->exec('SET CHARACTER SET utf8');
}
public function createPage($page)
{
$sth=$this->db->prepare("SELECT * FROM `pages` WHERE id=:page");
$sth->bindParam(":page", $page );
$sth->execute();
$row=$sth->fetch();
return $row;
}
public function createPageOfCatalog($id)
{
$sth=$this->db->prepare("SELECT `category_name` AS title, `desc`, `keywords` FROM `category` WHERE id=:id");
$sth->bindParam(":id", $id);
$sth->execute();
$row=$sth->fetch();
return $row;
}
public function createPageOfCard($id)
{
$sth=$this->db->prepare("SELECT `name` AS title, `desc`, `keywords` FROM `goods` WHERE id=:id");
$sth->bindParam(":id", $id);
$sth->execute();
$row=$sth->fetch();
return $row;
}
public function createGoods($id, $goods=array(), $pagenum=1)
{
$this->goods=new Goods($this->db, $id, $goods, $pagenum);
}
public function createFilter($id, $param=array())
{
$this->filter=new Filter($this->db, $id, $param);
}
public function createCard($id)
{
$this->card=new Card($this->db, $id);
}
public function getCategoryName($id)
{
$sth=$this->db->prepare("SELECT category_name FROM category WHERE id=:id");
$sth->bindParam(":id", $id);
$sth->execute();
$row=$sth->fetch();
return $row[0];
}
public function createCart()
{
$this->cart=new Cart($this->db);
}