wpdb->query returns different value to phpMyAdmin

You need to read the manual for the functions you’re using as all the information for how to debug is contained there.

$wpdb-query() description is very clear. The return value is:

(int|bool) Boolean true for CREATE, ALTER, TRUNCATE and DROP queries. Number of rows affected/selected for all other queries. Boolean false on error.

As mentioned in answers to your previous questions, you probably want something like $wpdb->getvar(), which returns one scalar value from a query.