fork download
  1. <?php
  2.  
  3.  
  4. class Student
  5. {
  6. public $firstName;
  7. public $lastName;
  8. public $sex;
  9. public $section;
  10. public $email;
  11. public $year;
  12. public $exams;
  13. public $isLocal;
  14.  
  15. public function __construct(Array $student) {
  16. $this->firstName = $student['firstName'];
  17. $this->lastName = $student['lastname'];
  18. $this->sex = $student['sex'];
  19. $this->section = $student['section'];
  20. $this->email = $student['email'];
  21. $this->year = $student['year'];
  22. $this->exams = $student['exams'];
  23. $this->isLocal = $student['isLocal'];
  24. }
  25.  
  26. /* Тут еще будет функция для проверки полей на валидность и возвращать юзеру данны где ошибка */
  27. }
  28.  
  29. class StudentMapper
  30. {
  31. protected $db;
  32.  
  33. public function __construct(PDO $db){
  34. $this->db = $db;
  35. }
  36.  
  37. public function saveStudent(Student $student){
  38. $STH = $this->db->prepare("INSERT into students (firstName, lastName, sex, section, email, year, exams, isLocal) values (?, ?, ?, ?, ?, ?, ?, ?);");
  39. $STH = $STH->execute($student);
  40. }
  41. }
  42.  
  43. $person = new Student($_POST);
  44. $SAT = new PDO('mysql:host=localhost;dbname=sat', 'root', '');
  45. $table = new StudentMapper($SAT);
  46. $table->saveStudent($person);
  47.  
  48. ?>
Runtime error #stdin #stdout #stderr 0.01s 20568KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Notice:  Undefined index: firstName in /home/0dKUJT/prog.php on line 18
PHP Notice:  Undefined index: lastname in /home/0dKUJT/prog.php on line 19
PHP Notice:  Undefined index: sex in /home/0dKUJT/prog.php on line 20
PHP Notice:  Undefined index: section in /home/0dKUJT/prog.php on line 21
PHP Notice:  Undefined index: email in /home/0dKUJT/prog.php on line 22
PHP Notice:  Undefined index: year in /home/0dKUJT/prog.php on line 23
PHP Notice:  Undefined index: exams in /home/0dKUJT/prog.php on line 24
PHP Notice:  Undefined index: isLocal in /home/0dKUJT/prog.php on line 25
PHP Fatal error:  Uncaught exception 'PDOException' with message 'could not find driver' in /home/0dKUJT/prog.php:46
Stack trace:
#0 /home/0dKUJT/prog.php(46): PDO->__construct('mysql:host=loca...', 'root', '')
#1 {main}
  thrown in /home/0dKUJT/prog.php on line 46