<?php
class mysql
{
  var $table;
  var $field;
  var $where;
  function open($host,$user,$pw,$dbname)
  {
    $con = mysql_connect($host,$user,$pw);
    mysql_select_db($dbname, $con);
    mysql_query("SET NAMES 'utf8'"); 
  }
  function close()
  {
    mysql_close();
  }
  function assignment()
  {
    $rs = mysql_query("SELECT ".$this->field." FROM ".$this->table." WHERE ".$this->where."");
    while($rs1 = mysql_fetch_array($rs))
    {
      $rs2[] = $rs1;
    }
	return $rs2;
  }
  function write()
  {
    mysql_query("INSERT INTO ".$this->table."(".$this->field.") VALUES (".$this->where.")");
  }
  function upgrade()
  {
    mysql_query("UPDATE ".$this->table." SET ".$this->field." WHERE ".$this->where."");
  }
  function delete()
  {
    mysql_query("DELETE FROM ".$this->table." WHERE ".$this->where."");
  }
  function exist($type)
  {
    if($type==1)
	{
      $rs = mysql_fetch_array(mysql_query("SELECT ".$this->field." FROM ".$this->table." WHERE ".$this->where.""));
	  if(empty($rs))
        return 0;
	  else
	    return $rs;
	}
	else
	{
	  $rs = mysql_num_rows(mysql_query("SELECT ".$this->field." FROM ".$this->table." WHERE ".$this->where.""));
	  return $rs;
	}
  }
  function mysubstr($str,$start,$len)
  {
    $tmpstr = ""; 
    $strlen = $start + $len; 
    for($i=0;$i<$strlen;$i++)
	{ 
      if(ord(substr($str,$i,1))>0xa0)
	  { 
        $tmpstr.=substr($str,$i,2); 
        $i++;
	  }
	  else 
        $tmpstr .= substr($str, $i, 1); 
    } 
    return $tmpstr; 
  }
}
error_reporting(0);
$tpl -> assign("core_version", "v3.3 UTF-8");
?>