码迷,mamicode.com
首页 > 其他好文 > 详细

增删改查

时间:2015-12-18 10:32:11      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

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

}
}

增删改查

标签:

原文地址:http://www.cnblogs.com/cocotian/p/5056156.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!