PHP Implementation of a Web Service Student Class
Model.php : Student Class (4)
// stor e () stores a student in the database
public functi o n store () {
$query = ' INSERT INTO ' . self :: $table .
' ( studentId , sname , fname , prog , tAddrId ,
pAddrId ) VALUES (? ,? ,? ,? ,? ,?) ' ;
// Prepare s t atemen t
$stmt = $this - > conn - > pr e pare ( $query ) ;
$stmt - > exe c u te ( arra y ( $this - > studentID , $this -> sname ,
$this - > fname , $this -> prog ,
$this - > tAddrId , $this -> pAddrId ));
return $this -> studen tId ;
}
// __to String () is called w h enever we need a string
// rep res e nta tion of an Student o b j e c t .
public functi o n __t o Strin g () {
return jso n _enc ode ( $this ,
JSO N_U NES CAP ED_ UN I CO DE | J SO N _U NES CAP ED_ SLA SHE S );
}
COMP519 Web Programming Lecture 29 Slide L29 – 24