I found this a fascinating problem, and while searching for a possible cause I found this topic which actually sounds plausible.
In short: you open connection resource $conn
within function scope. As such it makes sense that it is destroyed when leaving that scope. All resources stemming from that connection resource as such are automatically no longer valid, so that explains why the query resource also dies upon exiting the scope. If you look at it this way it makes sense too - how can a derived resource continue to exist without its logical parent resource. We're just spoilt by PHP that it usually doesn't care about this, but in C#/Java etc. it's plausible behaviour.
If this assumption is correct, the simplest solution is to put global $conn;
at the beginning of your squeal
function so it cannot get out of scope. Depending on the rest of the code you could implement a more elegant (and less potentially conflicting) solution, the implementation isn't really kosher anyway that it connects within a function and then expects followups to survive outside.