<?php 
class keyword_mod  extends HC_Controller
{
	public function __construct()
	{
		parent::__construct();
		if(empty($this -> db)){
			$this -> load_db();
		}
	}
 
	public function add_keyword( $newkeyword ='' , $type = 'art', $countval = 1 )
	{
		$keyid = '';
		if( $newkeyword != '')
		{
			//查询是否存在关键字
			$select_sql = " SELECT key_id FROM ".$this -> db -> prefix."keyword WHERE key_word ='".$newkeyword."' ";
			$idarray   = $this -> db -> select_one( $select_sql );

			if($idarray["key_id"]!='')
			{
				
				$upsql = " UPDATE  ".$this -> db -> prefix."keyword SET key_count = key_count + 1 WHERE key_id ='".$idarray["key_id"]."' ";
				$this -> db -> query_sql( $upsql );
				return $idarray["key_id"];
			}else{
				$insert_sql = " INSERT INTO `".$this -> db -> prefix."keyword` ( `key_word` , `key_is_up` , `key_count` ) VALUES (  '".$newkeyword."', '0', '$countval' )";
				return $this -> db ->  insert_sql( $insert_sql );
				
			}
		}
	}
} 