记录搜索关键字到数据库

//记录搜索关键字到数据库
public function AddSearchKey($SearchKey,$userinfo=''){
$cip=getip();
if($userinfo!=''){
$cus_id=$userinfo['cus_id'];
}else{
$cus_id=0;
}
//搜索关键字转拼音,以及拼音首字母
$Pinyin = new APPExtendChinesePinyin();
$pinyinall=$Pinyin->TransformWithoutTone($SearchKey);
$pinyinfirst=$Pinyin->TransformUcwords($SearchKey);
$Model=M('search_key');
$SearchList=$Model->where("key_word='" .$SearchKey. "'")->select();
if(count($SearchList)>0){
$sql="Update yd_search_key set search_num=search_num+1 where key_word='" .$SearchKey. "'";
}else{
$sql="INSERT INTO yd_search_key (key_word, key_word_pinyin, key_word_pinyin_first, is_show, search_num, search_order) VALUES('" .$SearchKey. "', '" .$pinyinall. "', '" .$pinyinfirst. "',0,1,0)";
}
$Dao=M();
$SearchList = $Dao->execute($sql);
$sql="INSERT INTO yd_hot_word(ctime,word,is_show,fm,ip,cus_id) values ('" .time(). "','" .$SearchKey. "',1,0,'" .$cip. "'," .$cus_id. ")";
$Dao=M();
$SearchList = $Dao->execute($sql);
return 'OK' ;
}

原文地址:https://www.cnblogs.com/mike1314/p/7168578.html