1--TEST--
2mysqli_stmt_get_warnings() - TODO
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifemb.inc');
7require_once('skipifconnectfailure.inc');
8
9require_once("connect.inc");
10
11if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
12	die(sprintf("skip Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
13		$host, $user, $db, $port, $socket));
14}
15
16if (!mysqli_query($link, "DROP TABLE IF EXISTS test") ||
17	!mysqli_query($link, "CREATE TABLE test(id SMALLINT)"))
18	die(sprintf("skip [%d] %s\n", $link->errno, $link->error));
19
20if (!@mysqli_query($link, "SET sql_mode=''") || !@mysqli_query($link, "INSERT INTO test(id) VALUES (100001)"))
21	die("skip Strict sql mode seems to be active. We won't get a warning to check for.");
22
23mysqli_query($link, "DROP TABLE IF EXISTS test");
24?>
25--FILE--
26<?php
27	require_once("connect.inc");
28
29	$tmp    = NULL;
30	$link   = NULL;
31
32	if (!is_null($tmp = @mysqli_stmt_get_warnings()))
33		printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
34
35	if (!is_null($tmp = @mysqli_stmt_get_warnings($link)))
36		printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
37
38	require('table.inc');
39
40	if (!$stmt = mysqli_stmt_init($link))
41		printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
42
43	if (false !== ($tmp = mysqli_stmt_get_warnings($stmt)))
44		printf("[004] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
45
46	if (!mysqli_stmt_prepare($stmt, "SET sql_mode=''") || !mysqli_stmt_execute($stmt))
47		printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
48
49	if (!mysqli_stmt_prepare($stmt, "DROP TABLE IF EXISTS test") || !mysqli_stmt_execute($stmt))
50		printf("[006] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
51
52	if (false !== ($tmp = mysqli_stmt_get_warnings($stmt)))
53		printf("[007] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
54
55	if (!mysqli_stmt_prepare($stmt, "CREATE TABLE test(id SMALLINT, label CHAR(1))") || !mysqli_stmt_execute($stmt))
56		printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
57
58	if (false !== ($tmp = mysqli_stmt_get_warnings($stmt)))
59		printf("[009] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
60
61	if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(id, label) VALUES (100000, 'a'), (100001, 'b')") ||
62		!mysqli_stmt_execute($stmt))
63		printf("[010] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
64
65	if (!is_object($warning = mysqli_stmt_get_warnings($stmt)))
66		printf("[011] Expecting mysqli_warning object, got %s/%s\n", gettype($warning), $warning);
67
68	if ('mysqli_warning' !== get_class($warning))
69		printf("[012] Expecting object of type mysqli_warning got type '%s'", get_class($warning));
70
71	if (!method_exists($warning, 'next'))
72		printf("[013] Object mysqli_warning seems to lack method next()\n");
73
74	$i = 0;
75	do {
76
77		if ('' == $warning->message)
78			printf("[014 - %d] Message should not be empty\n", $i);
79
80		if ('' == $warning->sqlstate)
81			printf("[015 - %d] SQL State should not be empty\n", $i);
82
83		if (0 == $warning->errno)
84			printf("[016 - %d] Error number should not be zero\n", $i);
85
86		$i++;
87
88	} while ($warning->next());
89
90	if (2 != $i)
91		printf("[017] Expected 2 warnings, got %d warnings\n", $i);
92
93	mysqli_stmt_close($stmt);
94
95	if (false !== ($tmp = mysqli_stmt_get_warnings($stmt)))
96		printf("[018] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
97
98	mysqli_close($link);
99	print "done!";
100?>
101--CLEAN--
102<?php
103	require_once("clean_table.inc");
104?>
105--EXPECTF--
106Warning: mysqli_stmt_get_warnings(): invalid object or resource mysqli_stmt
107 in %s on line %d
108
109Warning: mysqli_stmt_get_warnings(): Couldn't fetch mysqli_stmt in %s on line %d
110done!
111