<?

class item {

	protected $table_name;

	protected $sql;
	protected $statement;

	public function set($table_name) {
		$this->table_name = $table_name;
		$this->sql = $data->main_instance;
		$this->statement = $data->statement;
	}

	public function load($v=NULL) {
		$query = 'SELECT * FROM '.$this->table_name.'';
		$rows = $this->sql->get_rows($query, []);
		return $rows;
	}	

	public function _($v=NULL) {
		/*$object->log('insert update');
		$object->log($object->toJSON($v));*/
		$insert = $this->statement->generate($v, $this->table_name);
		$this->sql->_($insert, $v);
		$id = $v['id'];
		return $id;
	}

	public function delete($id) {
		$query = 'DELETE FROM '.$this->table_name.' WHERE id = ?';
		$this->sql->execute($query, [$id]);
	}

}

?>