Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Student
- {
- // member variables
- private $m_sNaam;
- private $m_sVoornaam;
- private $m_iGeboortejaar;
- function __set($p_sProperty, $p_vValue){
- switch ($p_sProperty)
- {
- case "Naam":
- $this->m_sNaam = $p_vValue;
- break;
- case "Voornaam":
- $this->m_sVoornaam = $p_vValue;
- break;
- case "Geboortejaar":
- if(is_numeric($p_vValue) /*&& $p_vValue < date("Y") && $p_vValue > date("Y")-120*/){
- $this->m_iGeboortejaar = $p_vValue;
- }
- else {
- throw new Exception("Geboortejaar incorrect!");
- }
- break;
- }
- }
- function __get($p_sProperty){
- switch ($p_sProperty)
- {
- case "Naam":
- return $this->m_sNaam;
- break;
- case "Voornaam":
- return $this->m_sVoornaam;
- break;
- case "Geboortejaar":
- return $this->m_iGeboortejaar;
- break;
- }
- }
- public function Save(){
- $dbserver = "localhost";
- $dbuser = "root";
- $dbpass = "root";
- $dbase ="lesphp";
- $link = new mysqli($dbserver,$dbuser,$dbpass, $dbase);
- if ($link->connect_error) {
- throw new Exception("connectie feiled");
- }
- else
- {
- $sql = "insert into tblStudent(
- studentNaam,
- studentVoornaam,
- studentGeboortejaar
- )
- values ('$this->Naam','$this->Voornaam',$this->Geboortejaar)";
- if($link->query($sql))
- {
- $link->close();
- }
- else
- {
- throw new Exception("Connectie gelukt, student kon niet worden opgeslaan.");
- }
- }
- }
- }
- ?>
- <?php
- /*
- function __construct($p_sNaam,$p_sVoornaam,$p_iGeboortejaar){
- $this->m_sNaam = $p_sNaam;
- $this->m_sVoornaam = $p_sVoornaam;
- $this->m_iGeboortejaar = $p_iGeboortejaar;
- }
- */
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement