Hi Marc,
I tried to solve this problem for a long time. It is weird how this error happens. If I remove the bottom part of this method(i.e code segment bellow my comment) and transfer it into sql.php everything works fine. But I can't see any reason why this way is wrong.