Warning: count(): syntax problem of the count () function

Try replacing this in the original code:

$page = $wpdb->get_row($req);

with this:

$page = $wpdb->get_row($req, ARRAY_A);

This will make it return an array instead of an object.

Then you can follow with this:

if ($page && isset($page['ID'])) {
    $category->id = $page['ID'];
} else {$category->id = 0;}