Hi,
i am using PHP objects generated by pog generator.but the save method does not seem to work.
why does this happen

pog generator ? umm.. Never heard that before.. What do you mean by save method ? Save what ? Could you post your code please ?

POG is php object generator. where php objects are generated and standard methods for saving and retrieving data are automatically generated.

Please refer to this site for further details

Code generated looks as follows. which can be saved in a standard .php format.

<?php
/*
This SQL query will create the table to store your object.


CREATE TABLE `courses` (
`coursesid` int(11) NOT NULL auto_increment,
`class` VARCHAR(4) NOT NULL,
`course_name` VARCHAR(255) NOT NULL,
`board` VARCHAR(20) NOT NULL,
`paid` BINARY NOT NULL,
`info` VARCHAR(500) NOT NULL,
`mean` FLOAT NOT NULL,
`no_of_tests_taken` INT NOT NULL,
`top_score` TINYINT NOT NULL, PRIMARY KEY  (`coursesid`)) ENGINE=MyISAM;
*/


/**
* <b>courses</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=courses&attributeList=array+%28%0A++0+%3D%3E+%27class%27%2C%0A++1+%3D%3E+%27course_name%27%2C%0A++2+%3D%3E+%27board%27%2C%0A++3+%3D%3E+%27paid%27%2C%0A++4+%3D%3E+%27info%27%2C%0A++5+%3D%3E+%27mean%27%2C%0A++6+%3D%3E+%27no_of_tests_taken%27%2C%0A++7+%3D%3E+%27top_score%27%2C%0A%29&typeList=array+%28%0A++0+%3D%3E+%27VARCHAR%284%29%27%2C%0A++1+%3D%3E+%27VARCHAR%28255%29%27%2C%0A++2+%3D%3E+%27VARCHAR%2820%29%27%2C%0A++3+%3D%3E+%27BINARY%27%2C%0A++4+%3D%3E+%27VARCHAR%28500%29%27%2C%0A++5+%3D%3E+%27FLOAT%27%2C%0A++6+%3D%3E+%27INT%27%2C%0A++7+%3D%3E+%27TINYINT%27%2C%0A%29
*/
include_once('class.pog_base.php');
class courses extends POG_Base
{
public $coursesId = '';


/**
* @var VARCHAR(4)
*/
public $class;


/**
* @var VARCHAR(255)
*/
public $course_name;


/**
* @var VARCHAR(20)
*/
public $board;


/**
* @var BINARY
*/
public $paid;


/**
* @var VARCHAR(500)
*/
public $info;


/**
* @var FLOAT
*/
public $mean;


/**
* @var INT
*/
public $no_of_tests_taken;


/**
* @var TINYINT
*/
public $top_score;


public $pog_attribute_type = array(
"coursesId" => array('db_attributes' => array("NUMERIC", "INT")),
"class" => array('db_attributes' => array("TEXT", "VARCHAR", "4")),
"course_name" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
"board" => array('db_attributes' => array("TEXT", "VARCHAR", "20")),
"paid" => array('db_attributes' => array("TEXT", "BINARY")),
"info" => array('db_attributes' => array("TEXT", "VARCHAR", "500")),
"mean" => array('db_attributes' => array("NUMERIC", "FLOAT")),
"no_of_tests_taken" => array('db_attributes' => array("NUMERIC", "INT")),
"top_score" => array('db_attributes' => array("NUMERIC", "TINYINT")),
);
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 courses($class='', $course_name='', $board='', $paid='', $info='', $mean='', $no_of_tests_taken='', $top_score='')
{
$this->class = $class;
$this->course_name = $course_name;
$this->board = $board;
$this->paid = $paid;
$this->info = $info;
$this->mean = $mean;
$this->no_of_tests_taken = $no_of_tests_taken;
$this->top_score = $top_score;
}



/**
* Gets object from database
* @param integer $coursesId
* @return object $courses
*/
function Get($coursesId)
{
$connection = Database::Connect();
$this->pog_query = "select * from `courses` where `coursesid`='".intval($coursesId)."' LIMIT 1";
$cursor = Database::Reader($this->pog_query, $connection);
while ($row = Database::Read($cursor))
{
$this->coursesId = $row;
$this->class = $this->Unescape($row);
$this->course_name = $this->Unescape($row);
$this->board = $this->Unescape($row);
$this->paid = $this->Unescape($row);
$this->info = $this->Unescape($row);
$this->mean = $this->Unescape($row);
$this->no_of_tests_taken = $this->Unescape($row);
$this->top_score = $this->Unescape($row);
}
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 $coursesList
*/
function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
{
$connection = Database::Connect();
$sqlLimit = ($limit != '' ? "LIMIT $limit" : '');
$this->pog_query = "select * from `courses` ";
$coursesList = 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]]) && $this->pog_attribute_type[$fcv_array[$i][0]][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]][0] != 'SET')
{
if ($GLOBALS == 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]) && $this->pog_attribute_type[$sortBy][0] != 'NUMERIC' && $this->pog_attribute_type[$sortBy][0] != 'SET')
{
if ($GLOBALS == 1)
{
$sortBy = "BASE64_DECODE($sortBy) ";
}
else
{
$sortBy = "$sortBy ";
}
}
else
{
$sortBy = "$sortBy ";
}
}
else
{
$sortBy = "coursesid";
}
$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))
{
$courses = new $thisObjectName();
$courses->coursesId = $row;
$courses->class = $this->Unescape($row);
$courses->course_name = $this->Unescape($row);
$courses->board = $this->Unescape($row);
$courses->paid = $this->Unescape($row);
$courses->info = $this->Unescape($row);
$courses->mean = $this->Unescape($row);
$courses->no_of_tests_taken = $this->Unescape($row);
$courses->top_score = $this->Unescape($row);
$coursesList[] = $courses;
}
return $coursesList;
}



/**
* Saves the object to the database
* @return integer $coursesId
*/
function Save()
{
$connection = Database::Connect();
$this->pog_query = "select `coursesid` from `courses` where `coursesid`='".$this->coursesId."' LIMIT 1";
$rows = Database::Query($this->pog_query, $connection);
if ($rows > 0)
{
$this->pog_query = "update `courses` set
`class`='".$this->Escape($this->class)."',
`course_name`='".$this->Escape($this->course_name)."',
`board`='".$this->Escape($this->board)."',
`paid`='".$this->Escape($this->paid)."',
`info`='".$this->Escape($this->info)."',
`mean`='".$this->Escape($this->mean)."',
`no_of_tests_taken`='".$this->Escape($this->no_of_tests_taken)."',
`top_score`='".$this->Escape($this->top_score)."' where `coursesid`='".$this->coursesId."'";
}
else
{
$this->pog_query = "insert into `courses` (`class`, `course_name`, `board`, `paid`, `info`, `mean`, `no_of_tests_taken`, `top_score` ) values (
'".$this->Escape($this->class)."',
'".$this->Escape($this->course_name)."',
'".$this->Escape($this->board)."',
'".$this->Escape($this->paid)."',
'".$this->Escape($this->info)."',
'".$this->Escape($this->mean)."',
'".$this->Escape($this->no_of_tests_taken)."',
'".$this->Escape($this->top_score)."' )";
}
$insertId = Database::InsertOrUpdate($this->pog_query, $connection);
if ($this->coursesId == "")
{
$this->coursesId = $insertId;
}
return $this->coursesId;
}



/**
* Clones the object and saves it to the database
* @return integer $coursesId
*/
function SaveNew()
{
$this->coursesId = '';
return $this->Save();
}



/**
* Deletes the object from the database
* @return boolean
*/
function Delete()
{
$connection = Database::Connect();
$this->pog_query = "delete from `courses` where `coursesid`='".$this->coursesId."'";
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 `courses` 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]]) && $this->pog_attribute_type[$fcv_array[$i][0]][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]][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);
}
}
}
?>

I am using smarty and the methods that are generated by POG (asabove can) be used.

php file where the POG method is included is as follows

class student
{
// database object
var $sql = null;
// smarty template object
var $tpl = null;
// error messages
var $error = null;
var $addStudent = null;
var $studInfo;
function student()
{


// instantiate the template object
$this->tpl = new mainClass_Smarty;
$this->sql = new apne_SQL;
}


function insertTestDetails(&$formvars)
{
$connection = Database::Connect();
$query = "start transaction";
if(!mysql_query($query, $connection))
return "Transaction Failed";



$testinput = new tests();
$testinput->test_name     = $formvars;
$testinput->expiry_period = $formvars.'-'.$formvars.'-'.$formvars;
$testinput->time_limit    = $formvars.':'.$formvars.':'.$formvars;
$testinput->coursesid     = $formvars;
$testinput->paid          ='0';
// $testinput->testsId = '23';
$testinput->mean = '0';
$testinput->top_score ='0';


$testinput->Save(); //this is the method that does not seem to work and i don't even receive an error message



if(!$testinput->Save())
echo 'error';



$connection = Database::Connect();
$query = "commit";
if(!mysql_query($query, $connection))
return "Commit Failed";


return "success";
}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.