xref: /PHP-8.3/ext/pdo_mysql/tests/bug46292.phpt (revision 902d6439)
1--TEST--
2Bug #46292 (PDO::setFetchMode() shouldn't requires the 2nd arg when using FETCH_CLASSTYPE)
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
8MySQLPDOTest::skip();
9?>
10--FILE--
11<?php
12
13    require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
14    $pdoDb = MySQLPDOTest::factory();
15
16
17    class myclass {
18        public $value;
19
20        public function __construct() {
21            printf("%s()\n", __METHOD__);
22        }
23    }
24
25    class myclass2 extends myclass { }
26
27    $pdoDb->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
28    $pdoDb->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
29
30    $pdoDb->query('DROP TABLE IF EXISTS testz');
31
32    $pdoDb->query('CREATE TABLE testz (name VARCHAR(20) NOT NULL, value INT)');
33
34    $pdoDb->query("INSERT INTO testz VALUES ('myclass', 1), ('myclass2', 2), ('myclass', NULL), ('myclass3', NULL)");
35
36    $stmt = $pdoDb->prepare("SELECT * FROM testz");
37
38    var_dump($stmt->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE | PDO::FETCH_GROUP));
39    $stmt->execute();
40
41    var_dump($stmt->fetch());
42    var_dump($stmt->fetch());
43    var_dump($stmt->fetchAll());
44?>
45--CLEAN--
46<?php
47require __DIR__ . '/mysql_pdo_test.inc';
48$db = MySQLPDOTest::factory();
49$db->exec('DROP TABLE IF EXISTS testz');
50?>
51--EXPECTF--
52bool(true)
53myclass::__construct()
54object(myclass)#%d (1) {
55  ["value"]=>
56  string(1) "1"
57}
58myclass::__construct()
59object(myclass2)#%d (1) {
60  ["value"]=>
61  string(1) "2"
62}
63myclass::__construct()
64array(2) {
65  [0]=>
66  object(myclass)#%d (1) {
67    ["value"]=>
68    NULL
69  }
70  [1]=>
71  object(stdClass)#%d (1) {
72    ["value"]=>
73    NULL
74  }
75}
76