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

Posted 1 month 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'   => [
        \PDO::ATTR_EMULATE_PREPARES => true
    ]

This however brings some some [url=https://michaelseiler.net/2016/07/04/dont-emulate-prepared-statements-pdo-mysql/]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.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.