<?php
/*
*
* -------------------------------------------------------
* CLASSNAME: Users
* GENERATION DATE: 20.08.2010
* CLASS FILE: E:\bryan\xampp\htdocs\bryClasses\sql_class_generator_081910/generated_classes/class.Users.php
* FOR MYSQL TABLE: users
* FOR MYSQL DB: msison
* -------------------------------------------------------
*
* CODE GENERATED BY: BRYAN JAYSON TAN
* DATE EDIT: MARCH 26 2010
* ADDED METHOD: init(), selectOne(), selectAll(), toString()
* EDITED METHOD: update(), delete()
* DATE EDIT: JULY 31 2010
* ADDED METHOD: doCount()
* DATE EDIT: AUGUST 19, 2010
* EDITED METHOD: selectOne, selectAll,and doCount make them static
* -------------------------------------------------------
*
*/
include_once(dirname(__FILE__)."/class.database.php");
// **********************
// CLASS DECLARATION
// **********************
class Users
{ // class : begin
// **********************
// ATTRIBUTE DECLARATION
// **********************
private $id; // KEY ATTR. WITH AUTOINCREMENT
private $firstname; // (normal Attribute)
private $lastname; // (normal Attribute)
private $username; // (normal Attribute)
private $password; // (normal Attribute)
private $database; // Instance of class database
// **********************
// CONSTRUCTOR METHOD
// **********************
function Users()
{
$this->database = new Database();
}
// **********************
// GETTER METHODS
// **********************
public function getId()
{
return $this->id;
}
public function getFirstname()
{
return $this->firstname;
}
public function getLastname()
{
return $this->lastname;
}
public function getUsername()
{
return $this->username;
}
public function getPassword()
{
return $this->password;
}
// **********************
// SETTER METHODS
// **********************
public function setId($val)
{
$this->id = $val;
}
public function setFirstname($val)
{
$this->firstname = $val;
}
public function setLastname($val)
{
$this->lastname = $val;
}
public function setUsername($val)
{
$this->username = $val;
}
public function setPassword($val)
{
$this->password = $val;
}
// **********************
// INIT METHOD
// **********************
public function init($row)
{
$this->id = $row->id;
$this->firstname = $row->firstname;
$this->lastname = $row->lastname;
$this->username = $row->username;
$this->password = $row->password;
}
// **********************
// TO STRING METHOD
// **********************
public function toString()
{
$s = '';
$s .= 'id: '.$this->id . ', ';
$s .= 'firstname: '.$this->firstname . ', ';
$s .= 'lastname: '.$this->lastname . ', ';
$s .= 'username: '.$this->username . ', ';
$s .= 'password: '.$this->password;
return $s;
}
// **********************
// SELECT METHOD / LOAD ALL
// **********************
public static function selectAll($criteria = null)
{
$objarray = array(); // list of objects
$sql = "SELECT users.* FROM users";
if ($criteria)
{
$sql.= " " . $criteria;
}
$users = new Users();
$result = $users->database->query($sql);
$result = $users->database->result;
while($row = mysql_fetch_object($result))
{
$users = new Users();
$users->init($row);
array_push($objarray,$users);
}
return $objarray;
}
// **********************
// SELECT METHOD / LOAD ONE
// **********************
public static function selectOne($id,$criteria = null)
{
$sql = "SELECT users.* FROM users WHERE id = $id";
if ($criteria)
{
$sql.= " " . $criteria;
}
$users = new Users();
$result = $users->database->query($sql);
$result = $users->database->result;
$rows = $users->database->rows;
if ($rows > 0){
$users->init(mysql_fetch_object($result));
return $users;
}else{
return null;
}
}
// **********************
// DELETE
// **********************
public function delete()
{
$sql = "DELETE FROM users WHERE id = $this->id;";
$result = $this->database->query($sql);
}
// **********************
// INSERT
// **********************
public function insert()
{
$this->id = ""; // clear key for autoincrement
$sql = "INSERT INTO users ( firstname,lastname,username,password ) VALUES ( '$this->firstname','$this->lastname','$this->username','$this->password' )";
$result = $this->database->query($sql);
$this->id = mysql_insert_id($this->database->link);
}
// **********************
// UPDATE
// **********************
public function update()
{
$sql = " UPDATE users SET firstname = '$this->firstname',lastname = '$this->lastname',username = '$this->username',password = '$this->password' WHERE id = $this->id ";
$result = $this->database->query($sql);
}
// **********************
// DO COUNT
// **********************
public static function doCount($criteria = null)
{
$sql = "SELECT COUNT(*) as count FROM users";
if ($criteria)
{
$sql.= " " . $criteria;
}
$users = new Users();
$result = $users->database->query($sql);
$result = $users->database->result;
$row = mysql_fetch_object($result);
return $row->count;
}
} // class : end
?>
|