Skip to content Skip to sidebar Skip to footer

Process For Pulling Data From A Sql Database

I want to make a program that pulls objects from a sql database and processes the objects against a set of functions before returning the data to the user. It will work like this

Solution 1:

Your class definition should define the properties of the object, not the values. It should be defined statically, not dynamically at runtime. At runtime you create instances of this class and populate the data for each instance.

Try something like this:

classFood{
   var$name;
   var$temp;
   var$texture;

   // Constructorpublicfunctionfood($name, $temp, $texture) {
      $this->name = $name;
      $this->temp = $temp;
      $this->texture = $texture;
   }

   publicfunctionbreaksDentures() {
      if($this->temp >= 15) && ($this->texture === 'hard')
         returntrue;
      elsereturnfalse;
   }
}

And use it like this:

functionprocessFoods($daterange) {
   $query = build_query_from_daterange($daterange);
   $result = mysql_query($query);

   while($row = mysql_fetch_assoc($result)) {
      $food = new Food($row['name'], $row['temp'], $row['texture']);
      // Now $food is an instance of the Food class populate with the values// from the db, e.g., 'ice cream', 0, 'hard'.if$food->breaksDentures() {
         print("Don't eat it");
      }
   }
}

P.S. You may want to brush up on your object-oriented concepts. Your question is a good one but indicates some confusion about OO basics.

Post a Comment for "Process For Pulling Data From A Sql Database"