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