link = mysql_connect($this->server,$this->user,$this->passwd) or die("Kunde inte connecta"); mysql_select_db($this->db, $this->link); } function select($what,$table,$where = NULL,$order = NULL,$limit = NULL) { #example syntax leDB.select("*","blogg","blogg_id = 5"); #example syntax2 leDB.select("blogg_id","comments",NULL,NULL,"date desc"); <-- this would for example take all comments for one bloggpost $sql = "select ".$what." from ".$table; if($where) $sql.=" where ".$where; if($order) $sql.=" order by".$order; if($limit) $sql.=" limit ".$limit; $this->result = mysql_query($sql) or die(mysql_error()."Could not run ".$sql); if ($this->numRows() > 1) { return $this->fetchAll(); } else { return $this->fetch(); } } function fetch() { return @mysql_fetch_assoc($this->result); } function fetchAll() { $i = 0; $data = array(); while ($r = leDB::fetch()) { $data[$i++] = $r; } return $data; } function numRows() { return @mysql_num_rows($this->result); } function latestID() { return @mysql_insert_id($this->link); } } class Blogg { var limit = 10; function Blogg() { } function getBlogg($blogg_id = NULL) { #ONLY GET ONE BLOG. FOR EXAMPLE TO USE WITH blogg.php?id=2314 if($blogg_id) { $blogg = new leDB(); $data = $blogg->select("*","blogg","blogg_id".$blogg_id); } else { $blogg = new leDB(); $data = $blogg->select("*","blogg",NULL,"date desc",$this->limit); # #Ditt användarnamn är:
#och ditt id är: # } return $data; } function numComments($blogg_id) { $comments = new leDB(); $comments->select("comment_id","comments"); return $comments->numRows(); } } ?>