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);
}