Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

global setting of PDO's setFetchMode(PDO::FETCH_ASSOC) [duplicate]

Tags:

php

pdo

Possible Duplicate:
Is is possible to set a default PDO fetch mode?

I have searched the internet and this site and could not find an solution.

Is there a way to apply $this->query->setFetchMode(PDO::FETCH_ASSOC); globally for all PDO queries? I find myself repeating the line over and over again.

I have tried applying it to the initial PDO connection: $this->connection->setFetchMode() but that throws an exception.

like image 679
Phil Avatar asked Dec 09 '22 19:12

Phil


1 Answers

Since 5.2

$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
like image 90
Wrikken Avatar answered Dec 11 '22 08:12

Wrikken