rendered paste body<?php
/*
This SQL query will create the table to store your object.
CREATE TABLE `testobj` (
`testobjid` int(11) NOT NULL auto_increment,
`var1` VARCHAR(255) NOT NULL,
`var2` VARCHAR(255) NOT NULL,
`var3` VARCHAR(255) NOT NULL, PRIMARY KEY (`testobjid`)) ENGINE=MyISAM;
*/
/**
* <b>testobj</b> class with integrated CRUD methods.
* @author Php Object Generator
* @version POG 3.0d / PHP5
* @copyright Free for personal & commercial use. (Offered under the BSD license)
* @link http://www.phpobjectgenerator.com/?language=php5&wrapper=pog&objectName=testobj&attributeList=array+%28%0A++0+%3D%3E+%27var1%27%2C%0A++1+%3D%3E+%27var2%27%2C%0A++2+%3D%3E+%27var3%27%2C%0A%29&typeList=array+%28%0A++0+%3D%3E+%27VARCHAR%28255%29%27%2C%0A++1+%3D%3E+%27VARCHAR%28255%29%27%2C%0A++2+%3D%3E+%27VARCHAR%28255%29%27%2C%0A%29
*/
include_once('class.pog_base.php');
class testobj extends POG_Base
{
public $testobjId = '';
/**
* @var VARCHAR(255)
*/
public $var1;
/**
* @var VARCHAR(255)
*/
public $var2;
/**
* @var VARCHAR(255)
*/
public $var3;
public $pog_attribute_type = array(
"testobjId" => array('db_attributes' => array("NUMERIC", "INT")),
"var1" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
"var2" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
"var3" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
);
public $pog_query;
/**
* Getter for some private attributes
* @return mixed $attribute
*/
public function __get($attribute)
{
if (isset($this->{"_".$attribute}))
{
return $this->{"_".$attribute};
}
else
{
return false;
}
}
function testobj($var1='', $var2='', $var3='')
{
$this->var1 = $var1;
$this->var2 = $var2;
$this->var3 = $var3;
}
/**
* Gets object from database
* @param integer $testobjId
* @return object $testobj
*/
function Get($testobjId)
{
$connection = Database::Connect();
$this->pog_query = "select * from `testobj` where `testobjid`='".intval($testobjId)."' LIMIT 1";
$cursor = Database::Reader($this->pog_query, $connection);
while ($row = Database::Read($cursor))
{
$this->testobjId = $row['testobjid'];
$this->var1 = $this->Unescape($row['var1']);
$this->var2 = $this->Unescape($row['var2']);
$this->var3 = $this->Unescape($row['var3']);
}
return $this;
}
/**
* Returns a sorted array of objects that match given conditions
* @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
* @param string $sortBy
* @param boolean $ascending
* @param int limit
* @return array $testobjList
*/
function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
{
$connection = Database::Connect();
$sqlLimit = ($limit != '' ? "LIMIT $limit" : '');
$this->pog_query = "select * from `testobj` ";
$testobjList = Array();
if (sizeof($fcv_array) > 0)
{
$this->pog_query .= " where ";
for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
{
if (sizeof($fcv_array[$i]) == 1)
{
$this->pog_query .= " ".$fcv_array[$i][0]." ";
continue;
}
else
{
if ($i > 0 && sizeof($fcv_array[$i-1]) != 1)
{
$this->pog_query .= " AND ";
}
if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
{
if ($GLOBALS['configuration']['db_encoding'] == 1)
{
$value = POG_Base::IsColumn($fcv_array[$i][2]) ? "BASE64_DECODE(".$fcv_array[$i][2].")" : "'".$fcv_array[$i][2]."'";
$this->pog_query .= "BASE64_DECODE(`".$fcv_array[$i][0]."`) ".$fcv_array[$i][1]." ".$value;
}
else
{
$value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$this->Escape($fcv_array[$i][2])."'";
$this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
}
}
else
{
$value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$fcv_array[$i][2]."'";
$this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
}
}
}
}
if ($sortBy != '')
{
if (isset($this->pog_attribute_type[$sortBy]['db_attributes']) && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'SET')
{
if ($GLOBALS['configuration']['db_encoding'] == 1)
{
$sortBy = "BASE64_DECODE($sortBy) ";
}
else
{
$sortBy = "$sortBy ";
}
}
else
{
$sortBy = "$sortBy ";
}
}
else
{
$sortBy = "testobjid";
}
$this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit";
$thisObjectName = get_class($this);
$cursor = Database::Reader($this->pog_query, $connection);
while ($row = Database::Read($cursor))
{
$testobj = new $thisObjectName();
$testobj->testobjId = $row['testobjid'];
$testobj->var1 = $this->Unescape($row['var1']);
$testobj->var2 = $this->Unescape($row['var2']);
$testobj->var3 = $this->Unescape($row['var3']);
$testobjList[] = $testobj;
}
return $testobjList;
}
/**
* Saves the object to the database
* @return integer $testobjId
*/
function Save()
{
$connection = Database::Connect();
$this->pog_query = "select `testobjid` from `testobj` where `testobjid`='".$this->testobjId."' LIMIT 1";
$rows = Database::Query($this->pog_query, $connection);
if ($rows > 0)
{
$this->pog_query = "update `testobj` set
`var1`='".$this->Escape($this->var1)."',
`var2`='".$this->Escape($this->var2)."',
`var3`='".$this->Escape($this->var3)."' where `testobjid`='".$this->testobjId."'";
}
else
{
$this->pog_query = "insert into `testobj` (`var1`, `var2`, `var3` ) values (
'".$this->Escape($this->var1)."',
'".$this->Escape($this->var2)."',
'".$this->Escape($this->var3)."' )";
}
$insertId = Database::InsertOrUpdate($this->pog_query, $connection);
if ($this->testobjId == "")
{
$this->testobjId = $insertId;
}
return $this->testobjId;
}
/**
* Clones the object and saves it to the database
* @return integer $testobjId
*/
function SaveNew()
{
$this->testobjId = '';
return $this->Save();
}
/**
* Deletes the object from the database
* @return boolean
*/
function Delete()
{
$connection = Database::Connect();
$this->pog_query = "delete from `testobj` where `testobjid`='".$this->testobjId."'";
return Database::NonQuery($this->pog_query, $connection);
}
/**
* Deletes a list of objects that match given conditions
* @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
* @param bool $deep
* @return
*/
function DeleteList($fcv_array)
{
if (sizeof($fcv_array) > 0)
{
$connection = Database::Connect();
$pog_query = "delete from `testobj` where ";
for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
{
if (sizeof($fcv_array[$i]) == 1)
{
$pog_query .= " ".$fcv_array[$i][0]." ";
continue;
}
else
{
if ($i > 0 && sizeof($fcv_array[$i-1]) !== 1)
{
$pog_query .= " AND ";
}
if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
{
$pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$this->Escape($fcv_array[$i][2])."'";
}
else
{
$pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$fcv_array[$i][2]."'";
}
}
}
return Database::NonQuery($pog_query, $connection);
}
}
}
?>