User Tools

Site Tools


kurs:entwickeln_mit_phpunit

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision Both sides next revision
kurs:entwickeln_mit_phpunit [2012/01/12 11:07]
mh
kurs:entwickeln_mit_phpunit [2012/01/12 12:43]
mh
Line 3: Line 3:
 <​code>​ <​code>​
 <?php <?php
 +
 +require_once '​PEAR/​Exception.php';​
  
 class Employee { class Employee {
   var $id, $last_name, $salary;   var $id, $last_name, $salary;
   var $db;   var $db;
-  ​+ 
 +  function Employee() { 
 +    $this->​db_connect();​ 
 +  } 
   private function db_connect() {   private function db_connect() {
-    $this->​db = oci_connect('​hr',​ '​hr',​ '​orcl'​);​ +    $this->​db = oci_connect('​hr',​ '​hr',​ '​orcl'​);​
   }   }
-  ​+
   function set_last_name($last_name) {   function set_last_name($last_name) {
     $this->​last_name = $last_name;     $this->​last_name = $last_name;
   }   }
-  ​+
   function read() {   function read() {
-    $this->​db_connect();​ + $q = oci_parse($this->​db,​ 
- $q = oci_parse($this->​db,​  +      "​select last_name ln, salary
-      "​select last_name ln, salary ​+
       from employees       from employees
-         where last_name = :​b_last_name"​);​ +         where last_name = :​b_last_name"​);​
     oci_bind_by_name     oci_bind_by_name
     ($q, ":​b_last_name",​ $this->​last_name);​     ($q, ":​b_last_name",​ $this->​last_name);​
     $r = oci_execute($q,​ OCI_DEFAULT);​     $r = oci_execute($q,​ OCI_DEFAULT);​
     $row = oci_fetch_array($q,​ OCI_ASSOC);     $row = oci_fetch_array($q,​ OCI_ASSOC);
-    $this->​salary = $row['​SALARY'​];​ +    ​if (!isset($row['​LN'​])) { 
-  }  +   throw new PEAR_Exception("​no employee "​.$this->​last_name 
-  +     , 404); 
 +
 +  
 + $this->​salary = $row['​SALARY'​];​ 
 +  
 +  } 
   function store() {}   function store() {}
-  ​+
   function __set($u, $a) {   function __set($u, $a) {
     die("​ERROR:​ you tried to set $u with $a");     die("​ERROR:​ you tried to set $u with $a");
Line 42: Line 53:
     die("​ERROR:​ you tried to call $u with $a");     die("​ERROR:​ you tried to call $u with $a");
   }   }
- 
 } }
 +
 </​code>​ </​code>​
  
kurs/entwickeln_mit_phpunit.txt · Last modified: 2014/09/10 21:22 (external edit)