Cannot access PHP stdClass property after PDO::FETCH_OBJ
I've successfully connected to an IBM i5 and the following lines:
$stmt = $dbh->query('select fpdesc from mylib.myfile');
$row = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($row);
echo '<br>$row[FPDESC] returns '.$row[FPDESC];
produce the foll开发者_运维知识库owing 2 lines of output:
array(1) {
["FPDESC"]=> string(30) "ATLANTA "
}
$row[FPDESC] returns ATLANTA
So far so good. But the following lines:
$stmt = $dbh->query('select fpdesc from mylib.myfile');
$obj = $stmt->fetch(PDO::FETCH_OBJ);
var_dump($obj);
echo '<br>$obj->FPDESC returns '.$obj->FPDESC;
produce the following 2 lines of output:
object(stdClass)#4 (1) {
["FPDESC"]=> string(30) "ATLANTA "
}
$obj->FPDESC returns
Why am I unable to echo the FPDESC property? The only thing I can think of is scoping, but I'm really at a loss as to the fix. Any help would be greatly appreciated.
your key name needs to match the case you used in your SQL statement.
so if
select fpdesc from mylib.myfile
it should be
$obj->fpdesc // not $obj->FPDESC.
With the same reasoning... if
select fpDESC from my lib.myfile
it should be
$obj->fpDESC
精彩评论