本文介紹了是否可以設(shè)置默認(rèn)的 PDO 獲取模式?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
在我檢索數(shù)據(jù)之前,我總是必須輸入:
Before I retrieve data I always have to type:
$STH->setFetchMode(PDO::FETCH_OBJ);
為了使我的代碼更具可讀性,如果我可以在某處設(shè)置默認(rèn)模式會(huì)很棒....
In the interest of making my code more readable it would be great if I could set a default mode somewhere....
謝謝!
編輯.我最初希望我可以將 PDO:FETCH_OBJ 添加到我運(yùn)行的 setAttribute 代碼中我連接到數(shù)據(jù)庫,但這似乎不起作用......
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);
這篇關(guān)于是否可以設(shè)置默認(rèn)的 PDO 獲取模式?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!