Oh, if that works fine, that means the function puts the quotes automatically. But the problem in your script probably comes from getAccountName return value. From the error you wrote, it seems to return false, so the quotes aren't put around it, unlike strings. You need to check what it returns before executing the query.