fork download
  1. <?php
  2. class DataBase
  3. {
  4. private $user = 'root';
  5. private $pass = '';
  6. private $dsn = "mysql:host=localhost;dbname=students_bd";
  7. private $opt = array(
  8. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  9. PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
  10. );
  11.  
  12. private function makeConnect()
  13. {
  14. $pdo = new PDO($this->dsn, $this->user, $this->pass, $this->opt);
  15. return $pdo;
  16. }
  17.  
  18. public function getData()
  19. {
  20. $pdo = $this->makeConnect();
  21. $sql = 'SELECT * FROM students ORDER BY name';
  22. echo "<table border=1 bordercolor=black>";
  23. echo "<tr><td>Имя</td><td>Фамилия</td><td>Пол</td><td>Группа</td>
  24. <td>Email</td><td>Средний Бал</td><td>Местный/Приезжий</td><td>Год Рождения</td>
  25. </tr>";
  26. foreach ($pdo->query($sql) as $students) {
  27. echo "<tr><td>".$students['Name']."&nbsp;</td><td>".$students['Surname']."&nbsp;</td>
  28. <td>".$students['Sex']."&nbsp;</td><td>".$students['GroupNumber']."&nbsp;</td>
  29. <td>".$students['Email']."&nbsp;</td><td>".$students['Mark']."&nbsp;</td>
  30. <td>".$students['Local']."&nbsp;</td><td>".$students['Birth Date']."&nbsp;</td></tr>";
  31. }
  32. echo "</table>";
  33.  
  34. }
  35.  
  36.  
  37.  
  38. }
  39. $page = new DataBase;
  40. $page->getData();
  41.  
Runtime error #stdin #stdout #stderr 0.02s 24448KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Fatal error:  Uncaught exception 'PDOException' with message 'could not find driver' in /home/FpeJS5/prog.php:14
Stack trace:
#0 /home/FpeJS5/prog.php(14): PDO->__construct('mysql:host=loca...', 'root', '', Array)
#1 /home/FpeJS5/prog.php(20): DataBase->makeConnect()
#2 /home/FpeJS5/prog.php(40): DataBase->getData()
#3 {main}
  thrown in /home/FpeJS5/prog.php on line 14