PHP Classes

File: Example.class.php

Recommend this page to a friend!
  Classes of Stephen P   Class Generator for MySQL Tables   Example.class.php   Download  
File: Example.class.php
Role: Sample output
Content type: text/plain
Description: Example *output* from this class
Class: Class Generator for MySQL Tables
Generate classes to access MySQL database tables
Author: By
Last change: changed priority
Date: 16 years ago
Size: 4,528 bytes
 

Contents

Class file image Download
<?php /** * Class : Example * Author : * Date : March 9, 2008, 11:15 am * Description : * * This class was auto-generated by ClassGenerator * (Stephen Powis, SPowis@fightjudge.com) */ class Example { private $userId=null; private $username=null; private $email=null; private $phone=null; private $age=null; private $joinDate=null; /** * Public Constructor * * @param int $id * @return Example */ public function Example($id) { $SQL = "select *, UNIX_TIMESTAMP(`join_date`) as `unixtime_join_date` from `userTable` where `user_id` = '".mysql_real_escape_string($id)."' limit 1"; $result = mysql_query($SQL) or die("Error in SQL Syntax: $SQL," . mysql_error()); if ($row = mysql_fetch_array($result)) { $this->_userId = $row['user_id']; $this->_username = $row['user_name']; $this->_email = $row['user_email']; $this->_phone = $row['user_phone']; $this->_age = $row['user_age']; $this->_joinDate = $row['unixtime_join_date']; } } // Getter Methods /** * Gets value of userId * * @param boolean $escape * @return int */ public function getUserId($escape=false) { if ($escape) return(htmlentities($this->_userId)); else return($this->_userId); } /** * Gets value of username * * @param boolean $escape * @return string */ public function getUsername($escape=false) { if ($escape) return(htmlentities($this->_username)); else return($this->_username); } /** * Gets value of email * * @param boolean $escape * @return string */ public function getEmail($escape=false) { if ($escape) return(htmlentities($this->_email)); else return($this->_email); } /** * Gets value of phone * * @param boolean $escape * @return string */ public function getPhone($escape=false) { if ($escape) return(htmlentities($this->_phone)); else return($this->_phone); } /** * Gets value of age * * @param boolean $escape * @return int */ public function getAge($escape=false) { if ($escape) return(htmlentities($this->_age)); else return($this->_age); } /** * Gets value of joinDate * * @param string $format * @return string */ public function getJoinDate($format="F j, Y, g:i a") { return(date($format,$this->_joinDate)); } // Setter Methods /** * sets the username value * * @param string $value * @return boolean */ public function setUsername($value) { // Set Database Field if ($this->_updateDBField("user_name",$value) === false) return(false); // Set Private Data Member $this->_username = $value; return(true); } /** * sets the email value * * @param string $value * @return boolean */ public function setEmail($value) { // Set Database Field if ($this->_updateDBField("user_email",$value) === false) return(false); // Set Private Data Member $this->_email = $value; return(true); } /** * sets the phone value * * @param string $value * @return boolean */ public function setPhone($value) { // Set Database Field if ($this->_updateDBField("user_phone",$value) === false) return(false); // Set Private Data Member $this->_phone = $value; return(true); } /** * sets the age value * * @param int $value * @return boolean */ public function setAge($value) { // Set Database Field if ($this->_updateDBField("user_age",$value) === false) return(false); // Set Private Data Member $this->_age = $value; return(true); } /** * sets the joinDate value * * @param datetime $value * @return boolean */ public function setJoinDate($value) { // Set Database Field if ($this->_updateDBField("join_date",$value) === false) return(false); // Set Private Data Member $this->_joinDate = $value; return(true); } // Private Helper Methods /** * Private method to set DB values * * @param string $field * @param string $value * @return boolean */ private function _updateDBField($field, $value) { $SQL = "update `userTable` set `".mysql_real_escape_string($field)."`='".mysql_real_escape_string($value)."' where `user_id`='".mysql_real_escape_string($this->_userId)."' limit 1"; $result = mysql_query($SQL); if ($result === false) return(false); else return(true); } }