I think repson must be right that you meant to use $query->fetchrow_array instead of $dbh->selectrow_array($query).

However, the $dbh->select... methods can take an already prepared statement handle as the first argument. This allows you to prepare the statement once ahead of time, and then execute it with select... many times. For example: