search-replace: query tables instead of relying on what's in wpdb

It's very likely that some plugins might create custom tables without properly registering them in the `$wpdb` global.

So, we should use the same mechanism we use when `--network` is passed.