_conn = mysql_connect($host, $user, $pass); $this->_db = mysql_select_db($db); } function query($sql, $return=0){ $this->result=mysql_query($sql); return $this->result; } function select($table, $items="*", $where=""){ if($where) $where=" WHERE ".$where; if($items=="*"){ $sitems=$items; }else{ for($i=0;$iSql("SELECT $sitems FROM `$table`$where"); while($row=mysql_fetch_array($result)) $rows[]=$row; return $rows; } function insert($table, $items, $values){ mysql_query("INSERT INTO `$table` ($sitems) VALUES ($svalues)"); return mysql_inserted_id(); } function update($table, $rid, $items, $values){ for($i=0;$i_conn = mysql_connect($host, $user, $pass, $db); $this->_db = mysql_select_db($db); } function SetSQL($fields="",$from="",$where="",$orderby="",$order=""){ if($fields) $this->fields=$fields; if($from) $this->table=$from; if($where) $this->where=$where; if($orderby) $this->orderby=$orderby; if($order) $this->order=$order; } function GetSQL(){ foreach($this->fields as $field) $fields.=",`$field`"; $fields=substr($fields,1); if($this->where) $where=" WHERE ".$this->where; if($this->orderby) $orderby=" ORDER BY `".$this->orderby."`"; if($this->limit){ //calculate pages $this->rowcount = mysql_result(mysql_query("SELECT COUNT(*) FROM `".$this->table."`"),0,0); $limit = max($this->limit, 1); $this->pages = ceil($this->rowcount / $limit); $this->page = min(max($this->page, 1), $this->pages); $offset = ($this->page - 1) * $limit; if($this->rowcount) $limit=" LIMIT ".$offset.", ".$limit; } return "SELECT $fields FROM `".$this->table."`".$where.$orderby." ".$this->order.$limit; } function RunSQL(){ $result=mysql_query($this->GetSQL()); $rows=array(); while($data=mysql_fetch_array($result)){ $rows[]=$data; } $this->SetRows($rows); } function SetRowLimit($limit){ $this->limit=$limit; } function SetRows($rows){ $this->rows=$rows; } function GetRows(){ return $this->rows; } } ?>