mapping tables in database with repective table class

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
zizou
Forum Newbie
Posts: 1
Joined: Thu Aug 28, 2008 12:25 am

mapping tables in database with repective table class

Post by zizou »

I need to create a class for each of the tables of the database. But i am having a problem to map the foreign key column.
Take for instance, table employee with eid,ename and deptno as attributes.
and table department with deptno,dname and location

class Employee {
private eid;
private ename;
private deptno;

//functions...
}

class Department {
private deptno;
private dname;
private location;

//functions...
}
Now how to build relationship between deptno in these two class.
i need to use these two class to find out the employee name when location is given.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: mapping tables in database with repective table class

Post by jayshields »

You'd be better off using an existing ORM like Outlet.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: mapping tables in database with repective table class

Post by Christopher »

Code: Select all

class Employee {
         private eid;
         private ename;
         private deptno;
 
         //functions...
}
 
class Department {
         private deptno;
         private dname;
         private location;
 
         public function findEmployees() {
             // fetch records using SELECT * FROM Employees WHERE deptno={$this->deptno}
             // return array of Employee objects
         }
}
(#10850)
Post Reply