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