Is is possible to set a default PDO fetch mode?

前端 未结 2 685
无人共我
无人共我 2020-11-28 08:46

Before I retrieve data I always have to type:

$STH->setFetchMode(PDO::FETCH_OBJ);

In the interest of making my code more readable it wou

2条回答
  •  醉梦人生
    2020-11-28 09:01

    $connection = new PDO($connection_string);
    $connection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
    

提交回复
热议问题