Page 1 of 1

mapping tables in database with repective table class

Posted: Fri Sep 19, 2008 5:04 am
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.

Re: mapping tables in database with repective table class

Posted: Fri Sep 19, 2008 5:28 am
by jayshields
You'd be better off using an existing ORM like Outlet.

Re: mapping tables in database with repective table class

Posted: Fri Sep 19, 2008 1:25 pm
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
         }
}