在我检索数据之前,我总是必须输入:
Before I retrieve data I always have to type:
$STH->setFetchMode(PDO::FETCH_OBJ);
为了使我的代码更具可读性,如果我可以在某处设置默认模式会很棒....
In the interest of making my code more readable it would be great if I could set a default mode somewhere....
谢谢!
编辑.我最初希望我可以将 PDO:FETCH_OBJ 添加到我运行的 setAttribute 代码中我连接到数据库,但这似乎不起作用......
Edit. I was originally hoping I could add PDO:FETCH_OBJ to the setAttribute code I run when I connect to the DB, but that doesn't seem to work...
$connection = new PDO($connection_string);
$connection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
这篇关于是否可以设置默认的 PDO 获取模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!