After using Hibernet in Java, I like the convenience brought by it.
But in PHP:
mysqli_result::fetch_object() is a good and great function. It can complete Relation's turing into Object.
For example:
A table named Machine in database. It consists of "MACHINE_ID" and "MACHINE_NAME".
$query = "selete * from method where METHOD_NAME'".$method_name."'";
$result = $mysqli->query($query);
if($obj = $result->fetch_object()){
$this->machine->machine_id = $obj->MACHINE_ID;
$this->machine->machine_name = $obj->MACHINE_NAME;
return true;
}
else
return false;
}
As naming "machine_id" and "machine_name" of Machine object's properties, we have to write two lines:
$this->machine->machine_id = $obj->MACHINE_ID;
$this->machine->machine_name = $obj->MACHINE_NAME;
but if we name "MACHINE_ID" and "MACHINE_NAME" in Method object(Method.class), the two lines will disappear.
Another way, we change table "machine"'s fields into "machine_id" and "machine_name". That means make them to be same as Machine object's properties. Then the two lines will also disappear.
Machine object means abstrated conception class named Machine.class.php corresponding to table "machine" in DB.
I like and recommend the "Another way" or just do as the original codes. Never use the way in red colored as capitalization always means constant.