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.
mapping tables in database with repective table class
Moderator: General Moderators
- 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
You'd be better off using an existing ORM like Outlet.
- 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
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)