Displaying articles with tag orm

Installing Pear and DB_DataObject

Posted by PunNeng, Wed Dec 07 23:18:00 UTC 2005

NOTICE: post นี้ ข้อมูลเก่าครับ ของใหม่ดีกว่า ว่ากันง่ายๆ เลย ผมขี้เกียจแก้ละ :)

มาที่การติดตั้งกัน ผมจะติดตั้งบน appserv บน Windows นะครับ ถ้ายังไม่มีก็ download หลังจากติดตั้ง appserv กันเสร็จเรียบร้อยแล้ว เริ่มเลยยย

เปิด http://go-pear.org/ จะเห็นว่าเป็น code php แล้ว save ทั้งหมดเป็น go-pear.php ไว้ใน php folder

นั้นแหละ จากนั้น เปิดหน้า dos ขึ้นมา เข้าไปใน php folder แล้วพิมพ์ว่า

php go-pear.php
มันจะมีตัวเลือกอยู่ ให้เลือกข้อ 7 แล้วใส่ path ของ php ลงไป แล้วทำตามขั้นตอนต่อไป ในหน้า dos ทั้งหมดตังแต่แรก จะขึ้นว่า
D:\appserv\php>php go-pear.php
Content-type: text/html
X-Powered-By: PHP/4.3.11

Welcome to go-pear!

Go-pear will install the 'pear' command and all the files needed by
it.  This command is your tool for PEAR installation and 
maintenance.

Use 'php  local' to install a local copy of PEAR.

Go-pear also lets you download and install the PEAR packages bundled
with PHP: DB, Net_Socket, Net_SMTP, Mail, XML_Parser, PHPUnit.


If you wish to abort, press Control-C now, or press Enter to continue:

HTTP proxy (http://user:password@proxy.myhost.com:port), or Enter for none::

Below is a suggested file layout for your new PEAR installation.  To
change individual locations, type the number in front of the
directory.  Type 'all' to change all of them or simply press Enter to
accept these locations.

 1. Installation prefix           : D:\appserv\php
 2. Binaries directory            : $prefix
 3. PHP code directory ($php_dir) : $prefix\pear
 4. Documentation base directory  : $php_dir\docs
 5. Data base directory           : $php_dir\data
 6. Tests base directory          : $php_dir\tests
 7. php.exe path                  : 

1-7, 'all' or Enter to continue: 7
php.exe path [] : d:\appserv\php

********************************************************
NOTICE! We found php.exe under d:/appserv/php\php.exe, it uses a cgi SAPI.
PEAR commandline tool works well with it.
If you have a CLI php.exe available, we recommand to use it.

php.exe (sapi: cgi) found.


Below is a suggested file layout for your new PEAR installation.  To
change individual locations, type the number in front of the
directory.  Type 'all' to change all of them or simply press Enter to
accept these locations.

 1. Installation prefix           : D:\appserv\php
 2. Binaries directory            : $prefix
 3. PHP code directory ($php_dir) : $prefix\pear
 4. Documentation base directory  : $php_dir\docs
 5. Data base directory           : $php_dir\data
 6. Tests base directory          : $php_dir\tests
 7. php.exe path                  : d:\appserv\php\php.exe

1-7, 'all' or Enter to continue:

The following PEAR packages are bundled with PHP: DB, Net_Socket, Net_SMTP,
Mail, XML_Parser, PHPUnit.
Would you like to install these as well? [Y/n] : y

Loading zlib: ok
Downloading package: PEAR-stable......ok
Downloading package: Archive_Tar-stable....ok
Downloading package: Console_Getopt-stable....ok
Downloading package: XML_RPC-stable....ok
Bootstrapping: PEAR...................(remote) ok
Bootstrapping: Archive_Tar............(remote) ok
Bootstrapping: Console_Getopt.........(remote) ok
Downloading package: DB...............ok
Downloading package: Net_Socket.......ok
Downloading package: Net_SMTP.........ok
Downloading package: Mail.............ok
Downloading package: XML_Parser.......ok
Downloading package: PHPUnit..........ok
Extracting installer..................ok
WARNING: channel "pear.php.net" has updated its protocols, use "channel-update p
ear.php.net" to update
warning: pear/PEAR requires package "pear/Archive_Tar" (version >= 1.3.1)
warning: pear/PEAR requires package "pear/Console_Getopt" (version >= 1.2)
pear/PEAR can optionally use package "pear/XML_RPC" (version >= 1.4.0)
pear/PEAR can optionally use package "pear/PEAR_Frontend_Web" (version >= 0.5.0)

pear/PEAR can optionally use package "pear/PEAR_Frontend_Gtk" (version >= 0.4.0)

install ok: channel://pear.php.net/PEAR-1.4.5
WARNING: channel "pear.php.net" has updated its protocols, use "channel-update p
ear.php.net" to update
install ok: channel://pear.php.net/Archive_Tar-1.3.1
WARNING: channel "pear.php.net" has updated its protocols, use "channel-update p
ear.php.net" to update
install ok: channel://pear.php.net/Console_Getopt-1.2
WARNING: channel "pear.php.net" has updated its protocols, use "channel-update p
ear.php.net" to update
install ok: channel://pear.php.net/XML_RPC-1.4.4
WARNING: channel "pear.php.net" has updated its protocols, use "channel-update p
ear.php.net" to update
install ok: channel://pear.php.net/DB-1.7.6
WARNING: channel "pear.php.net" has updated its protocols, use "channel-update p
ear.php.net" to update
install ok: channel://pear.php.net/Net_Socket-1.0.6
WARNING: channel "pear.php.net" has updated its protocols, use "channel-update p
ear.php.net" to update
pear/Net_SMTP can optionally use package "pear/Auth_SASL"
install ok: channel://pear.php.net/Net_SMTP-1.2.7
WARNING: channel "pear.php.net" has updated its protocols, use "channel-update p
ear.php.net" to update
install ok: channel://pear.php.net/Mail-1.1.9
WARNING: channel "pear.php.net" has updated its protocols, use "channel-update p
ear.php.net" to update
install ok: channel://pear.php.net/XML_Parser-1.2.7
WARNING: channel "pear.php.net" has updated its protocols, use "channel-update p
ear.php.net" to update
pear/PHPUnit can optionally use package "pear/PHP_Compat"
install ok: channel://pear.php.net/PHPUnit-1.3.2

*******************************************************
WARNING!  The include_path defined in the currently used php.ini does not
contain the PEAR PHP directory you just specified:

If the specified directory is also not in the include_path used by
your scripts, you will have problems getting any PEAR packages working.


Would you like to alter php.ini ? [Y/n] : y

php.ini  include_path updated.

Current include path           : .;c:\php4\pear
Configured directory           : D:\appserv\php\pear
Currently used php.ini (guess) : C:\WINDOWS\php.ini
Press Enter to continue:

The 'pear' command is now at your service at d:\appserv\php\pear.bat

** The 'pear' command is not currently in your PATH, so you need to
** use 'd:\appserv\php\pear.bat' until you have added
** 'D:\appserv\php' to your PATH environment variable.

Run it without parameters to see the available actions, try 'pear list'
to see what packages are installed, or 'pear help' for help.

For more information about PEAR, see:

  http://pear.php.net/faq.php
  http://cvs.php.net/co.php/pearweb/doc/pear_package_manager.txt?p=1
  http://pear.php.net/manual/

Thanks for using go-pear!



* WINDOWS ENVIRONMENT VARIABLES *
For convenience, a REG file is available under D:\appserv\php\PEAR_ENV.reg .
This file creates ENV variables for the current user.

Double-click this file to add it to the current user registry.


D:\appserv\php>
หลังจากเสร็จแล้ว เราจะได้ PEAR_ENV.reg เป็นตัว set environment variable แล้วก็ double click ที่ไฟล์นี้เลย เท่านี้ก็เป็นการเสร็จสิ้นการติดตั้ง PEAR แล้ว ต่อไปจะเป็นการติดตั้ง DB_DataObject นะครับ ยังอยู่กันที่หน้า dos ใน php folder นะ เราจะพิมพ์ต่อว่า
pecl install http://www.pear.php.net/get/DB_DataObject-1.7.15.tgz
แล้วมันจะเตือนเราว่า ต้องติดตั้ง Data ก่อน ก็พิมพ์ว่า
pecl install http://www.pear.php.net/get/Date-1.4.6.tgz
พอเสร็จแล้ว ก็ย้อนกลับไปติดตั้ง DB_DataObject-1.7.15.tgz ใหม่ ในหน้า dos ควรจะขึ้นว่า
D:\appserv\php>pecl install http://www.pear.php.net/get
/Date-1.4.6.tgz
downloading Date-1.4.6.tgz ...
Starting to download Date-1.4.6.tgz (53,535 bytes)
.............done: 53,535 bytes
WARNING: channel "pear.php.net" has updated its protocols, use "channel-update p
ear.php.net" to update
install ok: channel://pear.php.net/Date-1.4.6

D:\appserv\php>pecl install http://www.pear.php.net/get
/DB_DataObject-1.7.15.tgz

downloading DB_DataObject-1.7.15.tgz ...
Starting to download DB_DataObject-1.7.15.tgz (51,854 bytes)
.............done: 51,854 bytes
WARNING: channel "pear.php.net" has updated its protocols, use "channel-update p
ear.php.net" to update
Did not download dependencies: pear/Validate, use --alldeps or --onlyreqdeps to
download automatically
pear/DB_DataObject can optionally use package "pear/Validate" (version >= 0.1.1)

install ok: channel://pear.php.net/DB_DataObject-1.7.15

เท่านี้ก็เสร็จสิ้นการติดตั้ง

คราวหน้าจะเป็น tutorial ครับ จะดึงข้อมูลใน Database น้อยๆ ของเรา ขึ้นมาแสดง

ปล. อันนี้เป็นการติดตั้งในขณะที่เราต่อ internet อยู่ ถ้าเราจะ download package มา แล้วไปติดตั้งที่อื่น ก็ได้ มี command คอยสั่งอยู่ครับ

แก้ไขล่าสุด วันที่ 28 มิถุนายน 2550 เวลา 2.12 น.

ข้อมูลจาก
link เก่าไม่อยู่แล้ว link ใหม่อยู่ข้างบน

1 comment | Filed Under: General | Tags: orm

PEAR::DB_DataObject

Posted by PunNeng, Sun Dec 04 22:55:00 UTC 2005

มาเริ่ม Topic ใหม่กันที่ PEAR กันเลย

PEAR (PHP Extension and Application Repository) คืออะไร

PEAR เป็น Framework ที่รวบรวม library ต่างๆ ใหม่ๆ ที่สร้างขึ้นมาใหม่ ไว้ใช้กับ PHP โดยเฉพาะ ซึ่งมันจะช่วยอำนวยความสะดวกในการเขียนโปรแกรมขึ้นได้อีกมาก PEAR ถูกสร้างขึ้นเพื่อเตรียม
  • library ของชุด open-source สำหรับผู้ใช้ PHP
  • ระบบสำหรับ code ต่างๆ และ ระบบดูแลปรับปรุงที่เป็นส่วนๆ (Package maintenance)
  • ชุด code ที่ style ที่เป็นมาตรฐาน ซึ่งถูกกำหนดตาม linkนี้
  • PHP Extension Community Library (PECL)
ซึ่งในส่วนของ library ที่มีให้เราใช้กัน มีเยอะ เพราะมันเป็น open-source และมี community ค่อนข้างกว้าง เลยมีคนคอยพัฒนา library พวกนี้ ขึ้นมามาก ลองเข้าไปดูที่นี่ จะเห็น Package มากมาย บานเบอะ ครอบคลุมทุกการใช้งาน

แต่ที่คราวนี้คือ DB_DataObject ซึ่งจะเป็นตัวอธิบาย ORM ให้เห็นเป็นรูปเป็นร่างมากขึ้น

DB_DataObject

เป็นตัวช่วยสร้าง SQL และ Data Modeling Layer บนฝั่ง PEAR::DB มีจุดประสงค์เพื่อ

  • ช่วยสร้าง SQL และ Database เสมือน ในรูปแบบ Object Oriented
  • จับกลุ่ม source code ที่เกี่ยวข้องกับข้อมูลในข้อข้างบน
  • เตรียมชุด API ในการ access ไปยัง Database โดยต่อกับข้อมูลในข้อข้างบน

มาดูถ้าจะเขียนเป็น class แบบ ทั่วๆ ไป ไม่ได้อาศัย Framework อันอื่นมาช่วย จะได้ประมาณนี้

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
<?php
class MyPerson {

      // gets an array of data about the seleted person
      function getPerson($id) {
          global $db;
          $result = $db->query("SELECT * FROM person WHERE id=$id");
          return $result->fetchRow();
      }

      // example of checking a password.
      function checkPassword($username,$password) {
          global $db;
          $result = $db->query("SELECT username FROM person WHERE username='$username' AND password = '$password'");
          return $result->fetchRow();
      }

  }

  // get the persons details..
  $array = MyPerson::getPerson(12);
?>

จุดเจ๋งๆ ของมันเลยคือ ลักษณะของ class ที่เป็นการรวบรวมจับกลุ่ม Method1 ต่างๆ ในการเข้าถึง 1 table

(1)อันนี้เชิง OO จะใช้คำว่า Method แทน Function และ variable(ตัวแปร) จะใช้คำว่า Property(ตัวแปรในความหมายเดียวกัน) แทน

ต่อไป มาดูแบบที่พอเป็นในลักษณะ DataObject หรือ Container บ้าง ในส่วนของกลไกการเก็บข้อมูล

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
<?php
class MyPerson {

      var $id;  
      var $name;
      var $birthDate;


      // gets an array of data about the seleted person
      function get($id) {
          global $db;
          $result = $db->query("SELECT * FROM person WHERE id=$id");
          $array = $result->fetchRow();
          foreach($array as $key=>$value) {
              $this->$key = $value;
          }
      }

      function getAge() {
          return date('Y') - date('Y',$this->birthDate);
      }

  }
  // now get the person and display the age.
  $person = new MyPerson;
  $person->get(12);
  echo "{$person->name} is ". $person->getAge() . " years old";
?>

ในส่วนของ property id, name, birthDate จะเป็นชื่อของ column ใน DB เมื่อมัน loop ไปแล้ว จะวนตาม Property 3 ตัวนี้ อย่างที่เห็น หลังจากที่มันทำการเก็บ data ต่างๆ ลงใน Ojbect ตัวนี้แล้ว method ที่ถูกเพิ่มเข้ามา คือ getAge(และอันอื่นๆ ที่ถูกเพิ่มมาในอนาคต) ก็จะเข้าถึง Data เหล่านี้ได้

แต่ถ้าเราจะใช้ประโยชน์จาก property ต่างๆ ในการค้นหาใน Database ละ

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
<?php
class MyPerson {

      var $id;
      var $name;
      var $birthDate;


      // does the query based on the value of $this->name
      function find() {
          global $db;
          $this->result = $db->query("SELECT * FROM person WHERE name={$this->name}");
      }

      // fetches a row of data and sets the object 
      // variables to match it.

      function fetch() {
          $array = $this->result->fetchRow();
          if (empty($array)) {
              return false;
          }
          foreach($array as $key=>$value) {
              $this->$key = $value;
          }
      }

  }
  // now get the person and display the age.
  $person = new MyPerson;
  $person->name = "John";
  $person->find();
  while ($person->fetch()) {
    echo "a {$person->name} has a birthday on {$person->birthDate}<br />";
  }
?>

ตามนี้ เราจะระบุค่าใน property ก่อนที่จะใช้ find method ในการ query ตัว DataObject ก็จะมีลักษณะพฤติกรรมเหมือนๆ กันแบบนี้ เรายังสามารถเพิ่มค่าต่างๆ ในการค้นหาได้ด้วย whereAdd() method หรือจะใช้การเลือกโดยใช้ selectAdd() method ก็ยังได้

สังเกตุดู ว่าเราสามารถที่จะแต่งเติม code ที่เป็นของเราเองเพิ่มได้ ในแต่ละ table ไม่ยากๆ มันจะมี step ของมันอยู่ ก็สร้าง methods ตามนี้เลย

  • ขั้นตอนการ fetch : get, find, fetch
  • ขั้นตอนการปรับปรุง data : update, insert และ delete
  • แล้วก็ทำการผูก data ต่างๆ ใน object นั้นๆ

หลังจากที่ทำมันเสร็จแล้ว DB_DataObject ก็ถือกำเนิดขึ้นมา แต่ก็ยังไม่ดี เลยเอามาขัดเกลาด้วย

  • เพิ่ม Common simple configuration method ทำหน้าที่ config การติดต่อกับ Database
  • ถ้าจะใช้งาน Database ให้เร็ว ควรจะใช้ primary key ให้เป็นประโยชน์เยอะๆ
  • อย่าลืมตั้งค่า ตัว Debugger ด้วย มันจะช่วยให้เห็นว่าเรากำลังทำอะไรอยู่บ้าง
  • ในการตรวจความถูกต้องของข้อมูล ใช้ Strings กับ Integers ในการตรวจสอบจะดีมาก
  • สามารถที่จะสร้างความสัมพันธ์ระหว่างตารางอย่างซับซ้อนๆ ได้ ด้วยการใช้ secondary calls(ตอนหลังๆ ถ้าไม่ลืม จะมาแสดงให้ดู ว่าทำยังไง)
  • ทำการสร้างและปรับปรุงตารางของเราด้วย Database เสมือนของเรา(อันนี้ก็เหมือนกัน จะมาทำให้ดู)
  • ต่อเติมจาก package อันอื่นด้วย setForm() และ toArray() methods(จะทำให้ดูอีกเช่นกัน)

นะ มาดู class นี้กันต่อ

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
<?php
// this is the common configuration code - 
//place in a general site wide include file.

    // this  the code used to load and store 
    // DataObjects Configuration. 
    $options = &PEAR::getStaticProperty('DB_DataObject', 'options');

    // the simple examples use parse_ini_file, 
    // which is fast and efficient.
    // however you could as easily use wddx, 
    // xml or your own configuration array.
    $config = parse_ini_file('example.ini',TRUE);

    // because PEAR::getstaticProperty was 
    // called with and & (get by reference)
    // this will actually set the variable inside 
    // that method (a quasi static variable)
    $options = $config['DB_DataObject'];

     // this is normally contained in your DataObjects file 
     // (autogenerated by the generator)

    require_once 'DB/DataObject.php';


    // by extending the base class DB_DataObject 
    // you inherit all the common methods defined in it.
    class DataObjects_Person extends  DB_DataObject {

        var $id; // this is a primary id (it's specified in 
        // a config file - explained later)
        var $name;
        var $friend;

        // this is a simple function to get the persons 
        // friends..?

        function getFriends(){

            $personObject = $this->factory('person');

            // look for all people with their friend number 
            // matching this persons id.
            $personObject->friend = $this->id;

            // do the select query.
            $personObject->find();
            $array = array();

            // fetch the results into the object.
            while ($personObject->fetch()) {
                // use the clone to copy - not really needed 
                // but get used to it for PHP5

                $array[] = clone($personObject);
            }
            // return the results.
            return $array;

        }
    }


    // and this goes on your display code 

    // create a new person class..
    $person = DB_DataObject::Factory('person');

    // get the person using the primary key.
    $person->get(12);
    // get the friends.
    $friends = $person->getFriends();

    //  DB_DataObjects is designed to make print_r useable to 
    //  debug your applications.
    print_r($friends);
?>

class อันนี้แสดงให้เห็นถึงส่วนประกอบของ DB_DataObject ตั้งแต่การติดตั้ง options, objects พื้นฐานต่างๆ ก็จะโหลดจากไฟล์ .ini อย่างอัตโนมัติ แล้วก็กระบวณการ access ถึง

Database ส่วนครึงหลัง จะแสดงให้เห็นการ query และก็ดึงค่าออกมาโดยที่ $preson->get() จะต่อไปยัง Database โดยทำการ query แล้วก็ fetch ข้อมูลออกมาให้ object ตัวนึงที่รองรับอยู่ โดย query นี้คือ

SELECT * FROM person WHERE id=12;
SELECT * FROM person WHERE friend=12;

อีกตัวอย่าง ถ้าจะเปลี่ยนแปลงค่าใน Database เราจะใช้ update method

  1
  2
  3
  4
  5
  6
<?php
    $person = DB_DataObject::factory('person');
    $person->get(12);
    $person->name = 'Fred';
    $person->update();
?>

ส่วน methods อื่นๆ ชื่อมันก็คล้ายๆ กับ SQL statement แหละ ดูได้ที่นี่

แก้ไขล่าสุด วันที่ 20 มิถุนายน 2550 เวลา 3.22 น.

ข้อมูลจาก
PEAR :: Manual :: Introduction

0 comments | Filed Under: General | Tags: orm

Object Relational Mapping

Posted by PunNeng, Thu Dec 01 00:41:00 UTC 2005

ผมจะเรียกมันว่า ORM นะครับ

ORM คือ การ Links ให้ Database แบบ Relation ไปเป็นแบบ object-oriented language จะมีลักษณะแบบ virtual object database คือเป็น Database แบบเสมือนขึ้นมา เพราะพอตอนที่เข้าไปเก็บข้อมูล มันก็จะเข้าไปเก็บใน Database ที่เป็น Relation เหมือนเดิม

The term object/relational mapping (ORM) refers to the technique of mapping a data representation from an object model to a relational data model with a SQL-based schema.

ที่มา

อันนี้เป็นความชอบส่วนตัวครับ เพราะผมไม่ชอบ SQL Command เป็นอย่างมาก ถ้าจะเข้าถึง Database นะ ดูนี่ ง่ายๆ โดย PHP

แต่ถ้าเป็น ชุดที่ทำการ mapping แล้วล่ะ โดย DataObject ของ PEAR

สั้นกว่าเห็นๆ ไม่ต้องมี SQL มายุ่งให้ปวดหัว

ลองมานั่งนึกดูนะ มันจะไม่ค่อยมีอะไรใหม่ๆ เข้ามาอย่างเห็นได้ชัด มากมายนักหรอก ไม่ว่าจะเป็น PHP หรือ programming language ต่างๆ แต่มันจะมีตัวช่วยแบบนี้แหละ โผล่มาเรื่อยๆ โดยตัวนี้เนี่ย จะเป็นตัวช่วยอย่างมาก สำหรับนักพัฒนาที่ไม่ชอบไปยุ่งกับ SQL อย่างเช่นผม แต่ก็อย่าทิ้ง SQL ไปเลยซะล่ะ ถึงแม้ว่ามันจะมีตัวช่วยที่ง่ายๆ แบบนี้ เข้ามาก็ตาม

ORM Tools

มาดูเครื่องไม้เครื่องมือในการทำ ORM ดีกว่า ว่าแต่ละ language จะมีอะไรคอยช่วยบ้าง

PHP

  • AYLOOP (http://homepage.mac.com/sbarnum/code/alyoop/)
  • Changes (http://www.sitepoint.com/forums/showthread.php?t=214183)
  • DB_DataContainer  (http://www.appelsiini.net/~tuupola/php/DBDataContainer/): DBDataContainer is a PEAR compliant database persistence layer and data encapsulation class. Based on ActiveRecord.
  • DB_DataObject (PEAR) - official PEAR page  (http://pear.php.net/package/DB_DataObject)
  • DBTable (http://wiki.ciaweb.net/yawiki/index.php?area=DBTable): DB_Table is an object-oriented interface to a database table. PEAR-compliant. Based on ActiveRecord.
  • DBDO (PECL) (http://pecl.php.net/package/DBDO): Same as DB_DataObject, except as a PHP Extension
  • Entity (http://tanus.dotgeek.org/): The Entity framework is a generic object to database mapping architecture.
  • EZPDO (http://www.ezpdo.net): Eazy PHP Data Objects, a lightweight and easy-to-use object-relational mapping and data persistence solution for PHP
  • LDO (http://www.wojciechszela.com): Lightweight Data Objects, lightweight, open, feature rich and intuitive persistence solution for PHP
  • Metastorage (http://www.meta-language.net/metastorage.html): Metastorage is an application that automatically generates code for an Object Oriented API to store, retrieve and manipulate the data objects of classes described in a high level data model definition.
  • MyObjects (http://www.myobjects.org/): MyObjects is a set of tools for class generation, database schema generation and object persistence for Php 5 and MySql.
  • phpersistence (http://www.phpersistence.org/): phpersistence is an object oriented persistence layer for php, using transparent object relational mapping.
  • PhpOpenbiz (http://www.phpopenbiz.org/) PhpOpenbiz is a metadata-driven framework that implements MVC, ORM and object persistence. It also has an Eclipse plugin to help ORM configuration.
  • PPO (PHP Persistent Object) - Changes for PHP5
  • Perdure (http://sourceforge.net/projects/perdure/): Perdure is a transparent object relational persistence and query tool for PHP.
  • Propel (http://propel.phpdb.org): Propel is a full-service object persistence and query toolkit for PHP5.
  • phpCr (http://www.phpcr.org/): php Content Repository is a collection of interfaces. It aims to provide a framework for implementing jsr-170 (http://jcp.org/aboutJava/communityprocess/pfd/jsr170/index.html) for php.
  • DBOO & DBOO2  (http://www.sergiocarvalho.com/wiki/OpenSourceSoftware/#toc3): A PEAR-compliant orm for php4 and php5
  • Php Object Generator (POG)  (http://www.phpobjectgenerator.com/): Free Online Generator which automatically generates tested ORM code that you can use for your PHP4/PHP5 application.
  • Qcodo (http://www.qcodo.com/): Code-generation based PHP Development Framework that not only creates your ORM, but also creates classes for your forms. Architected to allow full customization to work hand-in-hand with infinite code regenerations. Recently presented at the Zend/PHP Conference (http://zend.kbconferences.com/).
ผมจะใช้ DB_DataObject ของ PEAR เป็นตัวอย่างในการอธิบายตอนต่อไปนะครับ

Java

เยอะมากครับ เอา links ไปดูเองดีกว่า http://www.javaskyline.com/database.html ผมเคยใช้ Hibernate อันเดียวคับ แต่เท่าที่ลองใช้มา ผมว่ามันครบเครื่องแล้ว

.Net

เยอะพอกันกับ Java เลย links เหมือนกัน http://sharptoolbox.com/Category74089b0a-1105-4389-b1db-eedf27e20cfb.aspx ฝั่ง .Net นี่ มี nHibernate ด้วยครับ ไม่เคยใช้เหมือนกัน แต่ดูจากค่ายแล้ว มัน Hibernate เหมือนกัน คงจะดีเหมือนๆ กับ Hibernate ของ Java

มีเครื่องไม้เครื่องมือในการอำนวยความครบครัน ชีวิตในการเขียนโปรแกรมจะง่ายขึ้นอีกเป็นกอง คุณๆ ทั้งหลาย เตรียมรับมือกับของพวกนี้หรือยังครับ

แก้ไขล่าสุด วันที่ 19 มิถุนายน 2550 เวลา 3.10 น.

ปล. ต้องแลกกันครับ ระหว่างการที่เราทำงานง่ายขึ้น แต่โปรแกรมเราทำงานนานกว่าเดิม ซึ่งผมเลือกให้เราทำงานง่ายขึ้นครับ แต่ถ้าระบบใหญ่ๆ ก็ต้องมาพิจารณากันอีกทีนึง

0 comments | Filed Under: General | Tags: orm

codegent: we're hiring