Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Charles Jay
- //Code Sample: UMS
- //OO Design
- class Employee {
- public $name;
- public $jobtitle;
- private $salary;
- private $ssn;
- function __construct($name) {
- $this->setName($name);
- }
- function getName() {
- return $this->name;
- }
- function setName($newName) {
- $this->name = $newName;
- }
- function getJobTitle() {
- return $this->jobtitle;
- }
- private function getSalary() {
- return $this->salary;
- }
- private function getSSN() {
- return $this->ssn;
- }
- }
- $employee = new Employee("John Doe");
- $employee->setName("Jane Doe");
- //MySQL
- $mysqli = new mysqli("localhost", "user", "pass", "employee");
- if ($mysqli->connect_errno) {
- echo "Failed to connect to MySQL Database\n";
- echo "Error: " $mysqli->connect_errno . " ". $mysqli->connect_error . "\n";
- exit;
- }
- function setJobTitle($newJobTitle, $employeeID) {
- $query = mysqli->prepare("update employees_table set jobTitle = ? where employeeID = ?");
- $query->bind_param("si", $newJobTitle, $employeeID);
- $query->execute();
- }
- $mysqli->close();
- //Directory Listing
- function listDir($dir=".") {
- if(is_dir($dir)) {
- if($opendir = opendir($dir)) {
- while(($file = readdir($opendir)) !== false) {
- if($file != "." && $file != "..") {
- echo '<a target="_blank" href="'.$dir.$file.'">'.$file.'</a><br>'."\n";
- }
- }
- closedir($opendir);
- }
- }
- }
- //Send Email
- $mailer = new PHPMailer(true);
- $mailer->Sender = "charlesjayuta@gmail.com";
- $mailer->SetFrom("charlesjayuta@gmail.com", "Charles Jay");
- $mailer->AddAddress("some@email.com");
- $mailer->Subject = "Some Could Go Here?!";
- $mailer->MsgHTML("<p>Hello, World!</p><p>-CJ</p>");
- $mailer->IsSMTP();
- $mailer->SMTPAuth = true;
- $mailer->SMTPSecure = "ssl";
- $mailer->Port = 465;
- $mailer->Host = "someserver?";
- $mailer->Username = "user";
- $mailer->Password = "pass";
- $mailer->Send();
- //MySQL DateTime Example
- function formatDateTime($rawInput) {
- $dateTime = new DateTime($rawInput);
- $mysqlFormat = $dateTime->format("Y-m-d H:i:s");
- return $mysqlFormat;
- }
- //Leap Year Calculator
- function leap_year($y) {
- if ((($y % 4 == 0) && ($y % 100 != 0)) || ($y % 400 == 0)) {
- echo "$y is a leap year\n";
- }
- else {
- echo "$y is not a leap year\n";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement