2
我在這裏虧本。不知道爲什麼我得到「stdClass」。我不應該從第一列獲得名字嗎?PDO :: FETCH_CLASSTYPE - 意外的結果
$sql = "SELECT cn, iso2, iso3, fid, sort FROM ct"; $stmt = $dbh->query($sql); $result = $stmt->fetch(PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE); var_dump($result); //expected - first: cn.col holds country names object(Brazil)[3] public 'iso2' => string 'BR' (length=2) public 'iso3' => string 'BRA' (length=3) public 'fid' => string '1' (length=1) public 'sort' => string '0' (length=1) //received object(stdClass)[3] public 'iso2' => string 'BR' (length=2) public 'iso3' => string 'BRA' (length=3) public 'fid' => string '1' (length=1) public 'sort' => string '0' (length=1)var_dump
的代碼看起來是正確的,你可以做一個'get_class($結果)'? – 2012-03-04 00:05:45
get_class($ result)獲取我:stdClass --- col.1(用於classname)是varchar,所以它應該沒問題(格式明智) - 沒有中斷或空格等。 – Jeffz 2012-03-04 00:28:47
想象得那麼奇怪,代碼看起來應該起作用。 – 2012-03-04 00:44:46