5

Are db_update->condition() and db_update->where() the same? If not, what are the differences?

1 Answer 1

9

condition() always involves a field/column name and a provided value (or an array of provided values). where() can contain arbitrary conditions (comparing fields against each other, can contain functions/expressions), it's just a string that is passed through.

condition() example, select everything where created is bigger than timestamp value.

$timestamp = 123465...;
$query->condition('created', $timestamp, '>');

where() example, select everything where changed is bigger than created.

$query->where('created < changed');

Everything that can be done with condition() can also be done with where(), but not the other way round. The following is the same as the condition() call.

$query->where('created > :timestamp', array(':timestamp' => $timestamp));

Works just fine, but is way more complicated. The basic rule is that condition() should be used whenever possible and if not, use where().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.