xref: /PHP-5.5/ext/pdo/tests/pdo_012.phpt (revision 0a2e6f72)
1--TEST--
2PDO Common: PDOStatement::setFetchMode
3--SKIPIF--
4<?php # vim:ft=php
5if (!extension_loaded('pdo')) die('skip');
6$dir = getenv('REDIR_TEST_DIR');
7if (false == $dir) die('skip no driver');
8require_once $dir . 'pdo_test.inc';
9PDOTest::skip();
10?>
11--FILE--
12<?php
13if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/');
14require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
15$db = PDOTest::factory();
16
17$db->exec('CREATE TABLE test(id int NOT NULL PRIMARY KEY, val VARCHAR(10), grp VARCHAR(10))');
18$db->exec('INSERT INTO test VALUES(1, \'A\', \'Group1\')');
19$db->exec('INSERT INTO test VALUES(2, \'B\', \'Group2\')');
20
21$SELECT = 'SELECT val, grp FROM test';
22
23$stmt = $db->query($SELECT, PDO::FETCH_NUM);
24var_dump($stmt->fetchAll());
25
26class Test
27{
28	function __construct($name = 'N/A')
29	{
30		echo __METHOD__ . "($name)\n";
31	}
32}
33
34unset($stmt);
35
36$stmt = $db->query($SELECT, PDO::FETCH_CLASS, 'Test');
37var_dump($stmt->fetchAll());
38
39unset($stmt);
40
41$stmt = $db->query($SELECT, PDO::FETCH_NUM);
42$stmt->setFetchMode(PDO::FETCH_CLASS, 'Test', array('Changed'));
43var_dump($stmt->fetchAll());
44
45?>
46--EXPECTF--
47array(2) {
48  [0]=>
49  array(2) {
50    [0]=>
51    string(1) "A"
52    [1]=>
53    string(6) "Group1"
54  }
55  [1]=>
56  array(2) {
57    [0]=>
58    string(1) "B"
59    [1]=>
60    string(6) "Group2"
61  }
62}
63Test::__construct(N/A)
64Test::__construct(N/A)
65array(2) {
66  [0]=>
67  object(Test)#%d (2) {
68    ["val"]=>
69    string(1) "A"
70    ["grp"]=>
71    string(6) "Group1"
72  }
73  [1]=>
74  object(Test)#%d (2) {
75    ["val"]=>
76    string(1) "B"
77    ["grp"]=>
78    string(6) "Group2"
79  }
80}
81Test::__construct(Changed)
82Test::__construct(Changed)
83array(2) {
84  [0]=>
85  object(Test)#%d (2) {
86    ["val"]=>
87    string(1) "A"
88    ["grp"]=>
89    string(6) "Group1"
90  }
91  [1]=>
92  object(Test)#%d (2) {
93    ["val"]=>
94    string(1) "B"
95    ["grp"]=>
96    string(6) "Group2"
97  }
98}
99