result[] = $data; } $this->rows = mysql_num_rows($query); $this->query = $queryString; return $this; } function get($table,$group='',$order=''){ if($order == ""){ $order = ""; }else{ $order = "order by $order"; } if($group == ""){ $group = ""; }else{ $group = "group by $group"; } $query = mysql_query("SELECT * FROM $table $group $order"); while($data = mysql_fetch_object($query)){ $this->result[] = $data; } $this->rows = mysql_num_rows($query); $this->query = "SELECT * FROM $table $order"; return $this; } function get_id($table,$id_field,$id){ $query = mysql_query("SELECT * FROM $table WHERE $id_field='$id'"); $this->result = mysql_fetch_object($query); $this->rows = mysql_num_rows($query); $this->query = "SELECT * FROM $table WHERE $id_field='$id'"; return $this; } function update_db($table,$fields,$id_field,$id){ $total_vars = count($fields); $counter = 1; $query_string = ""; foreach($fields as $name => $value){ if($counter < $total_vars){ $query_string .= $name."='$value',"; } if($counter == $total_vars){ $query_string .= $name."='$value'"; } $counter++; } $query = mysql_query("UPDATE $table SET $query_string WHERE $id_field='$id'"); if($query){ $this->result = "success"; $this->rows = 1; }else{ $this->result = "fail"; } $this->query = "UPDATE $table SET $query_string WHERE $id_field='$id'"; $this->error = $query; return $this; } function add_db($table,$fields){ $total_vars = count($fields); $counter = 1; $query_names = "("; $query_values = "("; foreach($fields as $name => $value){ if($counter < $total_vars){ $query_names .= $name.","; $query_values .= "'".$value."',"; } if($counter == $total_vars){ $query_names .= $name.")"; $query_values .= "'".$value."')"; } $counter++; } $query = mysql_query("INSERT INTO $table $query_names VALUES $query_values"); if($query){ $this->result = "success"; $this->rows = 1; $this->rowID = mysql_insert_id(); }else{ $this->result = "fail"; } $this->query = "INSERT INTO $table $query_names VALUES $query_values"; $this->error = $query; return $this; } function delete_db($table,$id_field,$id){ $query = mysql_query("DELETE FROM $table WHERE $id_field='$id'"); if($query){ $this->result = "success"; $this->rows = 1; }else{ $this->result = "fail"; } $this->query = "DELETE FROM $table WHERE $id_field='$id'"; $this->error = $query; return $this; } } ?>