Advertisement
Guest User

Untitled

a guest
Jun 13th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. <?php
  2.  
  3. class EmployeeService {
  4. var $username = "test";
  5. var $password = "test";
  6. var $server = "localhost";
  7. var $port = "3306";
  8. var $databasename = "testdrive_db";
  9. var $tablename = "employees";
  10.  
  11. var $connection;
  12. public function __construct() {
  13. $this->connection = mysqli_connect(
  14. $this->server,
  15. $this->username,
  16. $this->password,
  17. $this->databasename,
  18. $this->port
  19. );
  20.  
  21. $this->throwExceptionOnError($this->connection);
  22. }
  23.  
  24. public function getEmployees() {
  25. $stmt = mysqli_prepare($this->connection,
  26. "SELECT
  27. employees.id,
  28. employees.firstname,
  29. employees.lastname,
  30. employees.title,
  31. employees.departmentid,
  32. employees.officephone,
  33. employees.cellphone,
  34. employees.email,
  35. employees.street,
  36. employees.city,
  37. employees.state,
  38. employees.zipcode,
  39. employees.office,
  40. employees.photofile
  41. FROM employees");
  42.  
  43. $this->throwExceptionOnError();
  44.  
  45. mysqli_stmt_execute($stmt);
  46. $this->throwExceptionOnError();
  47.  
  48. $rows = array();
  49. mysqli_stmt_bind_result($stmt, $row->id, $row->firstname,
  50. $row->lastname, $row->title, $row->departmentid,
  51. $row->officephone, $row->cellphone, $row->email,
  52. $row->street, $row->city, $row->state,
  53. $row->zipcode, $row->office, $row->photofile);
  54.  
  55. while (mysqli_stmt_fetch($stmt)) {
  56. $rows[] = $row;
  57. $row = new stdClass();
  58. mysqli_stmt_bind_result($stmt, $row->id, $row->firstname,
  59. $row->lastname, $row->title, $row->departmentid,
  60. $row->officephone, $row->cellphone, $row->email,
  61. $row->street, $row->city, $row->state,
  62. $row->zipcode, $row->office, $row->photofile);
  63. }
  64.  
  65. mysqli_stmt_free_result($stmt);
  66. mysqli_close($this->connection);
  67.  
  68. return $rows;
  69. }
  70. }
  71. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement