增删改查

include "../tools/Tool.class.php";
class ShopModel
{
//查看所有
public function getAll(){
$getAll=array();
$a =0;
$mysql= Tool::getLink();
$sql="SELECT `demo1`.* FROM `demo1`";
$r=$mysql->query($sql);
while($row=$r->fetch_assoc()){
$getAll[$a]=$row;
$a++ ;
}

$r->free();
$mysql->close();
return $getAll;
}

//新增
public function add($id,$name){
$mysql=Tool::getLink();
$sql="INSERT INTO`demo1`(`id`,`name`) VALUES ($id,'$name')";

$mysql->query($sql);
$mysql->close();
}


//删除
public function delById($delId){
$mysql=Tool::getLink();
$sql="DELETE FROM demo1 where id=$delId";

$mysql->query($sql);
$mysql->close();
}

//查看
public function look($lookId){
$mysql=Tool::getLink();
$sql="SELECT `demo1`.* FROM `demo1` WHERE `id`=$lookId";
$bool=$mysql->query($sql);
$b=$bool->fetch_assoc();

$bool->free();
$mysql->close();
return $b;
}
//修改
public function modById($id,$name){
$mysql=Tool::getLink();
$sql="UPDATE `demo1` SET `name`='$name' WHERE `id`=$id";

$mysql->query($sql);
$mysql->close();

}

//加入购物车
public function addToCart($cartId){
$mysql=Tool::getLink();
$sql="SELECT `demo1`.* FROM `demo1` WHERE `id`=$cartId" ;
$r=$mysql->query($sql);
$row=$r->fetch_assoc();

$r->free();
$mysql->close();
return $row;
}

}
posted @ 2015-12-18 09:53  冰灬两重天  阅读(115)  评论(0编辑  收藏  举报