Login   Register  
PHP Classes
elePHPant
Icontem

File: class.compinfo.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of zengwenjie  >  genpo  >  class.compinfo.php  >  Download  
File: class.compinfo.php
Role: Sample output
Content type: text/plain
Description: one generate class
Class: genpo
Generate class to access table records as objects
Author: By
Last change:
Date: 6 years ago
Size: 5,821 bytes
 

Contents

Class file image Download
<?php
/**
 * A compinfo object represents a record of the table compinfo. 
 * @author Jevons <zeng@filetransfer.com>
 * @package Core
 * @version 1.0
 */

class compinfo{
 private $id;
 private $mylink;
 private $compname;
 private $address;
 private $post;
 private $email;
 private $phone;
 private $zip;
 private $memo;
 private $intime;
/*
 $obj_tmp->set_id($id);
 $obj_tmp->set_mylink($mylink);
 $obj_tmp->set_compname($compname);
 $obj_tmp->set_address($address);
 $obj_tmp->set_post($post);
 $obj_tmp->set_email($email);
 $obj_tmp->set_phone($phone);
 $obj_tmp->set_zip($zip);
 $obj_tmp->set_memo($memo);
 $obj_tmp->set_intime($intime);
*/

/*
 $obj_tmp->get_id();
 $obj_tmp->get_mylink();
 $obj_tmp->get_compname();
 $obj_tmp->get_address();
 $obj_tmp->get_post();
 $obj_tmp->get_email();
 $obj_tmp->get_phone();
 $obj_tmp->get_zip();
 $obj_tmp->get_memo();
 $obj_tmp->get_intime();
*/

 public function set_id($id)
{
$this->id=$id;
}
 public function get_id()
{
 return $this->id;
}
 public function set_mylink($mylink)
{
$this->mylink=$mylink;
}
 public function get_mylink()
{
 return $this->mylink;
}
 public function set_compname($compname)
{
$this->compname=$compname;
}
 public function get_compname()
{
 return $this->compname;
}
 public function set_address($address)
{
$this->address=$address;
}
 public function get_address()
{
 return $this->address;
}
 public function set_post($post)
{
$this->post=$post;
}
 public function get_post()
{
 return $this->post;
}
 public function set_email($email)
{
$this->email=$email;
}
 public function get_email()
{
 return $this->email;
}
 public function set_phone($phone)
{
$this->phone=$phone;
}
 public function get_phone()
{
 return $this->phone;
}
 public function set_zip($zip)
{
$this->zip=$zip;
}
 public function get_zip()
{
 return $this->zip;
}
 public function set_memo($memo)
{
$this->memo=$memo;
}
 public function get_memo()
{
 return $this->memo;
}
 public function set_intime($intime)
{
$this->intime=$intime;
}
 public function get_intime()
{
 return $this->intime;
}
	public function __construct($myId = null,$array = null){
		if($myId != null && is_numeric($myId) && $array == null){//init user object
			$this->db_load($myId);
		}elseif ($myId == null && is_array($array)){//use array of properties
			$this->set_properties_from_array($array);
		}elseif ($myId == null && $array == null){//maybe for creating a new user 
		}else {//invalid throw notice
	 	}
	}

	public function set_properties_from_array($array){ 

 isset($array['id']) ?$this->id = $array['id'] : $this->id;
 isset($array['mylink']) ?$this->mylink = $array['mylink'] : $this->mylink;
 isset($array['compname']) ?$this->compname = $array['compname'] : $this->compname;
 isset($array['address']) ?$this->address = $array['address'] : $this->address;
 isset($array['post']) ?$this->post = $array['post'] : $this->post;
 isset($array['email']) ?$this->email = $array['email'] : $this->email;
 isset($array['phone']) ?$this->phone = $array['phone'] : $this->phone;
 isset($array['zip']) ?$this->zip = $array['zip'] : $this->zip;
 isset($array['memo']) ?$this->memo = $array['memo'] : $this->memo;
 isset($array['intime']) ?$this->intime = $array['intime'] : $this->intime;
}

 public function db_load($id){
			global $applicationDb;
		$sDb = $applicationDb->getSlave();
		$sDb->SelectDB("FileTransfer_DB");

		$sDb = $applicationDb->getSlave();
		$query = "SELECT * FROM compinfo WHERE id=?";
		 
		$rs = $sDb->execute($query, Array($id));

		//if user was not found return false
		if($rs->EOF){
			//throw the error if this is requested
		 
			return false;
		}

		//set properties of the object from the database record
		foreach ($rs as $row){
			$this->set_properties_from_array($row);
		}
		return true;
		}
 public function db_save(){
if(is_null($this->id) || $this->id==""){
return $this->db_insert();
		}else{
			return $this->db_update();
		}
	}
private function db_insert(){

		 	global $applicationDb;

		$mDb = $applicationDb->getMaster();

		//Validate the supplied data before insert
	$query="INSERT INTO compinfo(id,mylink,compname,address,post,email,phone,zip,memo,intime
				 
			)
			VALUES(	?,?,?,?,?,?,?,?,?,?)
		";
$values = array($this->id,$this->mylink,$this->compname,$this->address,$this->post,$this->email,$this->phone,$this->zip,$this->memo,$this->intime);
$result = $mDb->execute($query, $values);
		if(!$result){ 
			echo mysql_error()."<br>";
			echo $query."<br>";
			return false;
		} //set and return the new id
		$this->set_id($mDb->Insert_ID());
		return $this->id;}
private function db_update(){

		global $applicationDb;
		$mDb = $applicationDb->getMaster();
		
		//Validate the supplied data before update
	 

		
		$query = "
			UPDATE compinfo
			SET  mylink=?,compname=?,address=?,post=?,email=?,phone=?,zip=?,memo=?,intime=?
			WHERE  id=?
		";

		$values = array( $this->mylink,$this->compname,$this->address,$this->post,$this->email,$this->phone,$this->zip,$this->memo,$this->intime,$this->id
		);

		$result = $mDb->execute($query, $values);

		//check if the query was succesfull
		if(!$result){
			echo mysql_error()."<br>";
			echo $query."<br>";
			 return false;
			 
		}

		return true;
	}
public function get_all_data(){

			$all_data="";
$all_data.=$this->get_mylink()."|";
$all_data.=$this->get_compname()."|";
$all_data.=$this->get_address()."|";
$all_data.=$this->get_post()."|";
$all_data.=$this->get_email()."|";
$all_data.=$this->get_phone()."|";
$all_data.=$this->get_zip()."|";
$all_data.=$this->get_memo()."|";
$all_data.=$this->get_intime()."|";
 return $all_data;
}
}
?>