Check for boolean false result from database query in SqlBagOStuff

Database::select() can return false, so we should check for it before
attempting to iterate on the result or to call methods on it.

Resolved conflicts:
	includes/objectcache/SqlBagOStuff.php

Cherry-Picked: I0862493305e5b2784422e0e94b3e62e734267795
Change-Id: I0862493305e5b2784422e0e94b3e62e734267795