Yes, this is correct. The recordset is server side code. server side PHP code can be on the page above the doctype.
The key is that when the page is delivered to the browser, the doctype tag should be at the top of the page.
The PHP code will be processed on the server, before the page is delivered to the browser. The PHP code on the page that uis before the doctype type tag is used to create objects that are used in the page. There should not be any PHP code to out p[ut to the page before the doctype tag.