I think I have solved it. When I updated my original php code, I just replaced my original connect and query calls with
$dsn = mysqli_connect() and
mysqli_query($dsn,$sql)
Apparently there is a new function I should be using as well:
$dsn->set_charset(‘utf8’);
Adding this after the connect makes it all work.