第一回用CI框架写MODEL层
程序员文章站
2022-06-13 13:10:02
...
第一次用CI框架写MODEL层
第一次用CI框架写model,不知道对不对,麻烦大家看一下...谢谢啦
class Article_model extends CI_Model {
function __construct(){
parent::__construct();
$this->load->model('modelDB');
}
function select_article($time,$name,$lable,$type,$details,$URL,$img){
$sql=$this->db->where('articleType',$type);
$art=$this->get('article');
//$q="select * from article where ";
if($sql->num_rows >0){
return $art;
}else{
return false;
}
}
function insert_article($time,$name,$lable,$type,$details,$URL,$img){
$data=array('articleName'=>$name,'articleTime'=>$time,'articleLable'=>$lable,'articleType'=>$type,'articleDetails'=>$details,'articleURL'=>$URL,'articleImg'=>$img);
$sql=$this->db->insert('article',$data);
if($sql->num_rows >0){
return $sql->row();
}else{
return false;
}
}
function update_article($id,$time,$name,$lable,$type,$details,$URL,$img){
$date=array('articleName'=>$name,'articleTime'=>$time,'articleLable'=>$lable,'articleType'=>$type,'articleDetails'=>$details,'articleURL'=>$URL,'articleImg'=>$img);
$q=$this->db->where('arrticlId',$id)->update('article',$date);
}
}
?>
------解决方案--------------------
你运行哈就知道对不对了嘛
还有你modelDB下面都没看到用为啥要load进来
第一次用CI框架写model,不知道对不对,麻烦大家看一下...谢谢啦
class Article_model extends CI_Model {
function __construct(){
parent::__construct();
$this->load->model('modelDB');
}
function select_article($time,$name,$lable,$type,$details,$URL,$img){
$sql=$this->db->where('articleType',$type);
$art=$this->get('article');
//$q="select * from article where ";
if($sql->num_rows >0){
return $art;
}else{
return false;
}
}
function insert_article($time,$name,$lable,$type,$details,$URL,$img){
$data=array('articleName'=>$name,'articleTime'=>$time,'articleLable'=>$lable,'articleType'=>$type,'articleDetails'=>$details,'articleURL'=>$URL,'articleImg'=>$img);
$sql=$this->db->insert('article',$data);
if($sql->num_rows >0){
return $sql->row();
}else{
return false;
}
}
function update_article($id,$time,$name,$lable,$type,$details,$URL,$img){
$date=array('articleName'=>$name,'articleTime'=>$time,'articleLable'=>$lable,'articleType'=>$type,'articleDetails'=>$details,'articleURL'=>$URL,'articleImg'=>$img);
$q=$this->db->where('arrticlId',$id)->update('article',$date);
}
}
?>
------解决方案--------------------
你运行哈就知道对不对了嘛
还有你modelDB下面都没看到用为啥要load进来
相关文章
相关视频
上一篇: 【求助】PHP域名限制及pfx解密