This is creating a SQL connection object and then a SQL command object. It's not doing anything else apart from that.
As far as your question about the SQL query itself:
It would appear that you have a self referencing categories table that defines a variable depth category tree. The query appears to be giving you a list of top level categories (i.e. ones with no [NULL] parent id) and the number of immediate child categories.
-Peter
compiledthoughts.com