一邊看書我碰到下面的函數來了:壞PHP類功能設計
/*
Update records in the database
@param String $table the table being updated
@param Array $changes array of changes field => value
@param String $condition the condition
@return Boolean
*/
public function updateRecords($table, array $changes, $condition)
{
$update = "UPDATE " . $table . " SET ";
foreach($changes as $field => $value)
{
$update .= "`" . $field . "` = '{$value}', ";
}
//remove trailing , (comma)
$update .= substr($update, 0, -1);
if($condition != '')
{
$update .= "WHERE " . $condition;
}
$this->executeQuery($update);
//Not sure why it returns true.
return true;
}
糾正我,如果我錯了,但是這是不是一個糟糕的設計功能,完全沒有數據過濾/檢查。而且大部分函數總是返回「真」。
更不用說SQL注入漏洞。 –