Stick the same query you are using in your PowerScript into a DataWindow, then trap the SQL Prepare event to see what raw SQL Syntax is being submitted to MySQL. My guess would be that something is going awry with the conversion of the syntax in the script to what is actually submitted to MySQL (possibly in the bind variable handling)...
Without understanding what the PowerBuilder Runtime is doing "behind the curtains" to cause a SQL error, you are fighting blind!
-PatP