本を読んでいるときに、次の機能に出くわしました。
/*
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;
}
私が間違っている場合は訂正してください。ただし、これはデータのフィルタリング/チェックがまったくない、設計が不適切な関数ではありません。そして何よりも、この関数は常に「true」を返します。