xref: /PHP-8.2/ext/pdo_mysql/tests/bug44327.phpt (revision b5a14e6c)
1--TEST--
2Bug #44327 (PDORow::queryString property & numeric offsets / Crash)
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
8MySQLPDOTest::skip();
9$db = MySQLPDOTest::factory();
10?>
11--FILE--
12<?php
13    require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
14    $db = MySQLPDOTest::factory();
15    $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
16
17    $stmt = $db->prepare("SELECT 1 AS \"one\"");
18    $stmt->execute();
19    $row = $stmt->fetch(PDO::FETCH_LAZY);
20    var_dump($row);
21    var_dump($row->{0});
22    var_dump($row->one);
23    var_dump($row->queryString);
24
25    print "----------------------------------\n";
26
27    @$db->exec("DROP TABLE test");
28    $db->exec("CREATE TABLE test (id INT)");
29    $db->exec("INSERT INTO test(id) VALUES (1)");
30    $stmt = $db->prepare("SELECT id FROM test");
31    $stmt->execute();
32    $row = $stmt->fetch(PDO::FETCH_LAZY);
33    var_dump($row);
34    var_dump($row->queryString);
35    @$db->exec("DROP TABLE test");
36
37    print "----------------------------------\n";
38
39    $stmt = $db->prepare('foo');
40    @$stmt->execute();
41    $row = $stmt->fetch();
42    var_dump($row->queryString);
43
44?>
45--EXPECTF--
46object(PDORow)#%d (2) {
47  ["queryString"]=>
48  string(17) "SELECT 1 AS "one""
49  ["one"]=>
50  string(1) "1"
51}
52string(1) "1"
53string(1) "1"
54string(17) "SELECT 1 AS "one""
55----------------------------------
56object(PDORow)#5 (2) {
57  ["queryString"]=>
58  string(19) "SELECT id FROM test"
59  ["id"]=>
60  string(1) "1"
61}
62string(19) "SELECT id FROM test"
63----------------------------------
64
65Warning: Attempt to read property "queryString" on bool in %s on line %d
66NULL
67