xref: /PHP-7.2/ext/mysqli/tests/bug32405.phpt (revision eb0e09f5)
1--TEST--
2Bug #32405 (mysqli->fetch() is returning bad data)
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7?>
8--FILE--
9<?php
10	require_once("connect.inc");
11
12	/*** test mysqli_connect 127.0.0.1 ***/
13	$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
14	mysqli_select_db($link, "test");
15	mysqli_query($link, "SET sql_mode=''");
16
17	/* two fields are needed. the problem does not occur with 1 field only selected. */
18	$link->query("CREATE TABLE test_users(user_id int(10) unsigned NOT NULL auto_increment, login varchar(50) default '', PRIMARY KEY (user_id))");
19	$link->query('INSERT INTO test_users VALUES (NULL, "user1"), (NULL, "user2"), (NULL, "user3"), (NULL, "user4")');
20
21
22	if ($stmt = $link->prepare("SELECT SQL_NO_CACHE user_id, login FROM test_users")) {
23			$stmt->execute();
24				$stmt->bind_result($col1, $col2);
25				while ($stmt->fetch()) {
26					var_dump($col1, $col2);
27			}
28			$stmt->close();
29	}
30
31	mysqli_query($link,"DROP TABLE test_users");
32	mysqli_close($link);
33?>
34--CLEAN--
35<?php
36require_once("connect.inc");
37if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
38   printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
39
40if (!mysqli_query($link, "DROP TABLE IF EXISTS test_users"))
41	printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
42
43mysqli_close($link);
44?>
45--EXPECTF--
46int(1)
47%s(5) "user1"
48int(2)
49%s(5) "user2"
50int(3)
51%s(5) "user3"
52int(4)
53%s(5) "user4"
54