bcast-bridge/web/include/db_Hlsw.class.php

83 lines
1.6 KiB
PHP
Raw Normal View History

2006-12-11 21:36:44 +01:00
<?php
class Hlsw {
private $inDB = false;
public $id;
public $vlanid;
public $flags;
public $ip = "0.0.0.0";
public $name;
private function fromRow($row) {
$retval = new Hlsw();
if ($row) {
$retval->inDB = true;
$retval->id = (int)$row['id'];
$retval->vlanid = (int)$row['vlanid'];
$retval->flags = (int)$row['flags'];
$retval->ip = (string)$row['ip'];
$retval->name = (string)$row['name'];
}
return $retval;
}
private function toSql() {
return "vlanid = '{$this->vlanid}',
flags = '{$this->flags}',
ip = INET_ATON('".mysql_real_escape_string($this->ip)."'),
name = '".mysql_real_escape_string($this->name)."'";
}
function load($id) {
$dbh = Database::getInstance();
$sql = "SELECT id, vlanid, flags, INET_NTOA(ip) AS ip, name
FROM hlsw
WHERE id = '{$id}'";
$dbh->query($sql);
return self::fromRow($dbh->fetch_assoc());
}
function save() {
$dbh = Database::getInstance();
if ($this->inDB) {
$sql = "UPDATE hlsw SET ".$this->toSql()."
WHERE id = '{$this->id}'";
$dbh->query($sql);
} else {
$sql = "INSERT hlsw SET ".$this->toSql();
$dbh->query($sql);
$this->iNDB = true;
$this->id = $dbh->insert_id();
}
}
function delete($id) {
$dbh = Database::getInstance();
$sql = "DELETE FROM hlsw
WHERE id = '{$id}'";
$dbh->query($sql);
}
function getAll() {
$dbh = Database::getInstance();
$sql = "SELECT id, vlanid, flags, INET_NTOA(ip) AS ip, name
FROM hlsw
ORDER BY ip";
$dbh->query($sql);
$retval = array();
while ($row = $dbh->fetch_assoc())
$retval[$row['id']] = self::fromRow($row);
return $retval;
}
}
?>