@ -1,22 +1,21 @@
<?php
<?php
class m odel {
class M odel {
public $errormsg = array();
public $errormsg = array();
private $table = array();
protected $table;
private $columns = array();
protected $columns = array();
private $values = array();
protected $values = array();
/**
/**
* id of database entry
* id of database entry
* @access private
* @access private
*/
*/
private $id;
protected $id;
protected $column_id;
public save() {
public function save() {
$db = new Database;
$db = new Database;
#Pseudecode if new
#Pseudecode if new
$db->insert( $this->table, $this->values );
$db->insert( $this->table, $this->values );
@ -24,18 +23,40 @@ class model {
$db->update( $this->table, $this->id, $this->values );
$db->update( $this->table, $this->id, $this->values );
}
}
public load( $parameter = array() ) {
public function load( $parameter = array() ) {
##pseudocode if where is key in parameters
$sql = '';
$db = new Database;
if (array_key_exists( 'where', $parameter) ) {
$w = $parameters['where']; # where = array('column', 'value' )
$w = $parameters['where']; # where = array('column', 'value' )
$sql = " WHERE $where['column'] = $where['value']";
$sql .= " WHERE $w[0] = $w[1]";
## elseif limit is key in parameters
} elseif ( array_key_exists('limit', $parameter ) ) {
$l = $parameter['limit']
$l = $parameter['limit'] # limit = array(start, length)
$sq = " LIMIT $l[1], $l[2]";
$sql .= " LIMIT $l[0], $l[1]";
}
$db->query("SELECT * FROM $this->table $sql");
$this->query = $ db->query("SELECT * FROM \{ $this->table \} $sql");
}
}
public function delete( $parameter = array() ) {
}
public function Assoc() {
$db = new Database();
return $db->getAssoc($this->query);
}
public function Array() {
$db = new Database();
return $db->getArray($this->query);
}
public function Object() {
$db = new Database();
return $db->getObject($this->query);
}
public function Row() {
$db = new Database();
return $db->getRow($this->query);
}
}
}