Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Armoletti's avatar

Query Builder not working with PDO::ATTR_EMULATE_PREPARES

Hello.

We are planning to migrate existing software gradually to use Laravel. Our database is PostgesSQL. I am currently trying to implement Passport to our system.

Our database connection apparently need to have option PDO::ATTR_EMULATE_PREPARES => true for some bouncer thing, not entirely sure why, and that is not up to me.

Having this option set causes errors with Query builder. If I have table with column type boolean, and try to fetch data based on that I get an error:

\DB::table('main.table')->where('somebooleanfield', true)->get();
ERROR: operator does not exist: boolean = integer 
LINE 1: select * from "main"."table" where "someboolanfield" = 1
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.

I did some digging and in \Illuminate\Database\Connection::prepareBindings() all boolean type bindings are casted to integer.

If the PDO::ATTR_EMULATE_PREPARES is not set everything works fine.

I try to find solution so we can use Query Builder with PDO::ATTR_EMULATE_PREPARES, any thoughts?

My config/database.php entry:

'connections' => [  
  'pgsql' => [  
     'driver' => 'pgsql',  
     'url' => '',  
     'host' => env('DB_HOST', '...'),  
     'port' => env('DB_PORT', '...'),  
     'database' => env('DB_DATABASE', '...'),  
     'username' => env('DB_USERNAME', '...'),  
     'password' => env('DB_PASSWORD', '...'),  
     'charset' => 'utf8',  
     'prefix' => '',  
     'prefix_indexes' => true,  
     'schema' => 'main',  
     'sslmode' => 'prefer',  
     'options' => array(  
        PDO::ATTR_EMULATE_PREPARES => true,  
     ),  
  ],
]
0 likes
1 reply

Please or to participate in this conversation.