--TEST-- PDO Common: PDOStatement::setFetchMode --EXTENSIONS-- pdo --SKIPIF-- --FILE-- exec('CREATE TABLE test012(id int NOT NULL PRIMARY KEY, val VARCHAR(10), grp VARCHAR(10))'); $db->exec("INSERT INTO test012 VALUES(1, 'A', 'Group1')"); $db->exec("INSERT INTO test012 VALUES(2, 'B', 'Group2')"); $SELECT = 'SELECT val, grp FROM test012'; $stmt = $db->query($SELECT, PDO::FETCH_NUM); var_dump($stmt->fetchAll()); class TestClass { public $val; public $grp; function __construct($name = 'N/A') { echo __METHOD__ . "($name)\n"; } } unset($stmt); $stmt = $db->query($SELECT, PDO::FETCH_CLASS, TestClass::class); var_dump($stmt->fetchAll()); unset($stmt); $stmt = $db->query($SELECT, PDO::FETCH_NUM); $stmt->setFetchMode(PDO::FETCH_CLASS, TestClass::class, array('Changed')); var_dump($stmt->fetchAll()); ?> --CLEAN-- --EXPECTF-- array(2) { [0]=> array(2) { [0]=> string(1) "A" [1]=> string(6) "Group1" } [1]=> array(2) { [0]=> string(1) "B" [1]=> string(6) "Group2" } } TestClass::__construct(N/A) TestClass::__construct(N/A) array(2) { [0]=> object(TestClass)#%d (2) { ["val"]=> string(1) "A" ["grp"]=> string(6) "Group1" } [1]=> object(TestClass)#%d (2) { ["val"]=> string(1) "B" ["grp"]=> string(6) "Group2" } } TestClass::__construct(Changed) TestClass::__construct(Changed) array(2) { [0]=> object(TestClass)#%d (2) { ["val"]=> string(1) "A" ["grp"]=> string(6) "Group1" } [1]=> object(TestClass)#%d (2) { ["val"]=> string(1) "B" ["grp"]=> string(6) "Group2" } }