The only way I can replicate this exact error message on a select is by providing a null byte into it. I can see the null byte in my debugger, but I cannot see it in the browser (which makes sense). How you got the null byte I couldn't tell; I did mine by manually adding it in:
$query = "SELECT * FROM `" . $databaseName . chr(0) . "`.`core_class` ORDER BY `clsid`;";
Which gave me the error:
Error: (1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
All other situations present either differing errors or a description of the cause.
Delete the line completely and manually retype it in.