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("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 (NULL !== ($tmp = mysqli_stmt_get_warnings($stmt)))
44		printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
45
46	if (!mysqli_stmt_prepare($stmt, "DROP TABLE IF EXISTS test") || !mysqli_stmt_execute($stmt))
47		printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
48
49	if (false !== ($tmp = mysqli_stmt_get_warnings($stmt)))
50		printf("[006] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
51
52	if (!mysqli_stmt_prepare($stmt, "CREATE TABLE test(id SMALLINT, label CHAR(1))") || !mysqli_stmt_execute($stmt))
53		printf("[007] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
54
55	if (false !== ($tmp = mysqli_stmt_get_warnings($stmt)))
56		printf("[008] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
57
58	if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(id, label) VALUES (100000, 'a'), (100001, 'b')") ||
59		!mysqli_stmt_execute($stmt))
60		printf("[009] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
61
62	if (!is_object($warning = mysqli_stmt_get_warnings($stmt)))
63		printf("[010] Expecting mysqli_warning object, got %s/%s\n", gettype($warning), $warning);
64
65	if ('mysqli_warning' !== get_class($warning))
66		printf("[011] Expecting object of type mysqli_warning got type '%s'", get_class($warning));
67
68	if (!method_exists($warning, 'next'))
69		printf("[012] Object mysqli_warning seems to lack method next()\n");
70
71	$i = 0;
72	do {
73
74		if ('' == $warning->message)
75			printf("[013 - %d] Message should not be empty\n", $i);
76
77		if ('' == $warning->sqlstate)
78			printf("[014 - %d] SQL State should not be empty\n", $i);
79
80		if (0 == $warning->errno)
81			printf("[015 - %d] Error number should not be zero\n", $i);
82
83		$i++;
84
85	} while ($warning->next());
86
87	if (2 != $i)
88		printf("[016] Expected 2 warnings, got %d warnings\n", $i);
89
90	mysqli_stmt_close($stmt);
91
92	if (NULL !== ($tmp = mysqli_stmt_get_warnings($stmt)))
93		printf("[015] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
94
95	mysqli_close($link);
96	print "done!";
97?>
98--CLEAN--
99<?php
100	require_once("clean_table.inc");
101?>
102--EXPECTF--
103Warning: mysqli_stmt_get_warnings(): invalid object or resource mysqli_stmt
104 in %s on line %d
105
106Warning: mysqli_stmt_get_warnings(): Couldn't fetch mysqli_stmt in %s on line %d
107done!