A point of PHP: mysqli_result::fetch_object() and ORM
来源:互联网 发布:知乎数据库设计 编辑:程序博客网 时间:2024/06/04 17:45
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.
- A point of PHP: mysqli_result::fetch_object() and ORM
- arrayDB, a New and Easy PHP ORM
- Calculating The Logical Height and Point Size of a Font
- Calculating The Logical Height and Point Size of a Font
- php的mysqli_result类
- C# Main point of a NotePad
- CareerCup Fermat point of a traingle
- php连接数据库后fetch_object()、fetch_all()、fetch_array()的用法
- PHP: Send the Authorization token in a header instead of on the querystring and 读取 XML
- Float and the form of expression of floating-point number in memory
- Point of sale software
- Point of Intersection
- zoj1199-Point of Intersection
- POS(Point Of Sales)
- Visibility of Point Cloud
- ZOJ1199-Point of Intersection
- Point and Pixel
- Point and Circle
- net读取url页面一
- jsp ajax 简单进度条 上传文件
- net读取url页面二
- 使用Windows的shutdown来操纵关机
- Windows中远程桌面强制登录控制台
- A point of PHP: mysqli_result::fetch_object() and ORM
- 通过VBS 获取系统所有服务信息
- sql语句中如何去掉空格 ?
- 浅谈多态
- 值传递还是引用传递
- 海量数据处理 (转)
- Windows Server 2008 R2 DC( Domain Controller )上安裝 SPS2010
- OnPaint和OnDraw的区别
- 面向对象的程序设计