Advertisement
Guest User

Untitled

a guest
Jun 24th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. <?php
  2.  
  3. //Charles Jay
  4. //Code Sample: UMS
  5.  
  6. //OO Design
  7. class Employee {
  8.  
  9. public $name;
  10. public $jobtitle;
  11. private $salary;
  12. private $ssn;
  13.  
  14. function __construct($name) {
  15. $this->setName($name);
  16. }
  17.  
  18. function getName() {
  19. return $this->name;
  20. }
  21.  
  22. function setName($newName) {
  23. $this->name = $newName;
  24. }
  25.  
  26. function getJobTitle() {
  27. return $this->jobtitle;
  28. }
  29.  
  30. private function getSalary() {
  31. return $this->salary;
  32. }
  33.  
  34. private function getSSN() {
  35. return $this->ssn;
  36. }
  37.  
  38.  
  39. }
  40.  
  41. $employee = new Employee("John Doe");
  42. $employee->setName("Jane Doe");
  43.  
  44. //MySQL
  45. $mysqli = new mysqli("localhost", "user", "pass", "employee");
  46. if ($mysqli->connect_errno) {
  47. echo "Failed to connect to MySQL Database\n";
  48. echo "Error: " $mysqli->connect_errno . " ". $mysqli->connect_error . "\n";
  49. exit;
  50. }
  51.  
  52. function setJobTitle($newJobTitle, $employeeID) {
  53. $query = mysqli->prepare("update employees_table set jobTitle = ? where employeeID = ?");
  54. $query->bind_param("si", $newJobTitle, $employeeID);
  55. $query->execute();
  56. }
  57.  
  58. $mysqli->close();
  59.  
  60. //Directory Listing
  61. function listDir($dir=".") {
  62. if(is_dir($dir)) {
  63. if($opendir = opendir($dir)) {
  64. while(($file = readdir($opendir)) !== false) {
  65. if($file != "." && $file != "..") {
  66. echo '<a target="_blank" href="'.$dir.$file.'">'.$file.'</a><br>'."\n";
  67. }
  68. }
  69. closedir($opendir);
  70. }
  71. }
  72. }
  73.  
  74. //Send Email
  75. $mailer = new PHPMailer(true);
  76.  
  77. $mailer->Sender = "charlesjayuta@gmail.com";
  78. $mailer->SetFrom("charlesjayuta@gmail.com", "Charles Jay");
  79. $mailer->AddAddress("some@email.com");
  80. $mailer->Subject = "Some Could Go Here?!";
  81. $mailer->MsgHTML("<p>Hello, World!</p><p>-CJ</p>");
  82.  
  83. $mailer->IsSMTP();
  84. $mailer->SMTPAuth = true;
  85. $mailer->SMTPSecure = "ssl";
  86. $mailer->Port = 465;
  87. $mailer->Host = "someserver?";
  88. $mailer->Username = "user";
  89. $mailer->Password = "pass";
  90.  
  91. $mailer->Send();
  92.  
  93. //MySQL DateTime Example
  94. function formatDateTime($rawInput) {
  95. $dateTime = new DateTime($rawInput);
  96. $mysqlFormat = $dateTime->format("Y-m-d H:i:s");
  97. return $mysqlFormat;
  98. }
  99.  
  100. //Leap Year Calculator
  101. function leap_year($y) {
  102. if ((($y % 4 == 0) && ($y % 100 != 0)) || ($y % 400 == 0)) {
  103. echo "$y is a leap year\n";
  104. }
  105. else {
  106. echo "$y is not a leap year\n";
  107. }
  108.  
  109. }
  110.  
  111. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement