Skip to content

Commit

Permalink
add.relation example added
Browse files Browse the repository at this point in the history
  • Loading branch information
irvingleonard committed Jun 4, 2014
0 parents commit 01facbf
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
22 changes: 22 additions & 0 deletions examples/add.relation/database-mysql_v5.x.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
CREATE TABLE student (
id_student INT(11) KEY AUTO_INCREMENT,
identification_number VARCHAR(11) NOT NULL,
name varchar(50) NOT NULL,
age INT(2) NULL,
preferences TEXT
);

CREATE TABLE teacher (
id_teacher INT(11) KEY AUTO_INCREMENT,
professorship_number VARCHAR(11) NOT NULL,
name varchar(50) NOT NULL,
experience_time INT(2) NULL,
marital_status TINYINT(1),
last_university_payment_date DATE
);

CREATE TABLE relation_student_teacher (
id_relation_student_teacher INT(11) KEY AUTO_INCREMENT,
id_student INT(11),
id_teacher INT(11)
)
8 changes: 8 additions & 0 deletions examples/add.relation/student.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
class student extends ODBObject{
public $identification_number;
public $name;
public $age;
public $preferences;
}
?>
15 changes: 15 additions & 0 deletions examples/add.relation/teacher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
// constants for marital status
define("SINGLE", 0x01, true);
define("MARRIED", 0x02, true);
define("DIVORCED", 0x03, true);
define("WIDOWED", 0x04, true);

class teacher extends ODBObject{
public $professorship_number;
public $name;
public $experience_time;
public $marital_status; // constants
public $contract_date; // date
}
?>
18 changes: 18 additions & 0 deletions examples/add.relation/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
require_once "../objectDB/objectDB-mysql-v3.0.php"; // this will include first
require_once "student.php";
require_once "teacher.php";

// create, set values and save a new student
$student = new student();
$student->setDataFromParamsList(3025,'Salvi Pascual',24,'color=orange,grossery=pie,serie=futurama');
$student->save();

// create, set values and save a new teacher
$teacher = new teacher();
$teacher->setDataFromParamsList('math201','Stephen W. Hawking',37,MARRIED,date("Y-m-d"));
$teacher->save();

// create relation between
$student->addRelation($teacher); // same than: $teacher->addRelation($student);
?>

0 comments on commit 01facbf

Please sign in to comment.