Dopple
06-17-2008, 08:42 AM
I have been looking at this section of the php manual, http://uk3.php.net/manual/en/language.oop5.overloading.php.
I have been coding the following class and am wondering how the __get and __set functions should connect to the database in order to get the info from, and put the info into the database. The frustrating thing is I have done OOP at college with Java but it was a while ago and we never did any work with database integration.
Thanks in advance for any help people can give me.
<?php
class Item{
public $itName;
public $itId;
public $itClass;
public $itTime;
private $data;
function __construct(){
}
public function __set($name, $val){
$this->data[$name] = $val;
}
public function __get($name){
if (array_key_exists($name)) {
return $this->data[$name];
}
}
//generate html to display form
function displayForm() {
echo '
<form action="item.php" method="post">
<label for="itemName">Item Name</label>
<input type="text" name="itemName" /><br />
<label for="itemClass">Item Class</label>
<input type="text" name="itemClass" /><br />
<input name="submit" value="Submit" type="submit" /><input name="reset" value="Reset" type="reset" />
</form>';
}
}
?>
I have been coding the following class and am wondering how the __get and __set functions should connect to the database in order to get the info from, and put the info into the database. The frustrating thing is I have done OOP at college with Java but it was a while ago and we never did any work with database integration.
Thanks in advance for any help people can give me.
<?php
class Item{
public $itName;
public $itId;
public $itClass;
public $itTime;
private $data;
function __construct(){
}
public function __set($name, $val){
$this->data[$name] = $val;
}
public function __get($name){
if (array_key_exists($name)) {
return $this->data[$name];
}
}
//generate html to display form
function displayForm() {
echo '
<form action="item.php" method="post">
<label for="itemName">Item Name</label>
<input type="text" name="itemName" /><br />
<label for="itemClass">Item Class</label>
<input type="text" name="itemClass" /><br />
<input name="submit" value="Submit" type="submit" /><input name="reset" value="Reset" type="reset" />
</form>';
}
}
?>