Query bug workaround - the correct way to do it? ( \PDO::ATTR_EMULATE_PREPARES )

Posted 5 months ago by Axeia

Hello, I have a query that on my live server (but not on the test server - yeah that's confusing) throws a "General error: 1615 Prepared statement needs to be re-prepared" after some Googling people seem to get around this by adding this to config/database.php

    'options'   => [

This however brings some some [url=]security concerns[/url] with it. So instead what I did was put this around my query (that I know to be safe as it only uses values already validated and in the database.

            $pdo = \DB::connection()->getPdo();
            $pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);

           //Query :)

            $pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);

I'm just kinda wondering why no one else seems to have done this, wouldn't this be the smarter/saver way to do it?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.