如何从$ this-> v中删除“dato”?并且仍然在$ sql字符串中。
OUTPUT(var_dump($ this-> v)):
array (size=4)
':kategori' => string 'Youstube' (length=8)
':link' => string 'http://urls' (length=11)
':navn' => string 'Rss feeds' (length=9)
':dato' => string 'NOW()' (length=5)
OUTPUT(echo $ sql)
更新rss_kategori SET kategori =:kategori,link =:link,navn =:navn,dato = NOW()
CODE:
$classVars = get_class_vars(get_class($this));
$sql .= "UPDATE {$this->table} SET ";
foreach ($classVars as $key => $value) {
if ($key == 'v' || $key == 'db' || $key == 'id' || $key == 'table' || $key ==
'table_id') {
continue;
}
$keys = "";
$values = "";
$keys .= $key;
if ($this->$key == 'NOW()') {
$values .= $this->$key . ",";
} else {
$values .= ":" . $key . ",";
}
$this->v[":" . $key] = $this->$key;
$sql .= "{$keys} = " . $values . " ";
}
$sql = substr($sql, 0, -2) . " WHERE {$this->table_id} = '{$this->id}'";
答案 0 :(得分:2)
请试试这个:
$key = ':dato';
$arr = $this->v;
if (array_key_exists($key, $this->v) {
unset($arr[$key]);
$this->v = $arr;
}
答案 1 :(得分:1)
尝试使用unset()
功能。
unset($this->v['dato']);