1--TEST--
2mysqli_stmt_bind_param() - Binding with very high number of columns
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifemb.inc');
7require_once('skipifconnectfailure.inc');
8?>
9--INI--
10memory_limit=256M
11--FILE--
12<?php
13	/*
14	The way we test the INSERT and data types overlaps with
15	the mysqli_stmt_bind_result test in large parts. There is only
16	one difference. This test uses mysqli_query()/mysqli_fetch_assoc() to
17	fetch the inserted values. This way we test
18	mysqli_query()/mysqli_fetch_assoc() for all possible data types
19	in this file and we test mysqli_stmt_bind_result() in the other
20	test -- therefore the "duplicate" makes some sense to me.
21	*/
22	require_once("connect.inc");
23
24	if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
25		printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
26			$host, $user, $db, $port, $socket);
27		exit(1);
28	}
29
30	$cols = 2500;
31
32	list($old_max_allowed_packet) = $link->query("SELECT @@max_allowed_packet")->fetch_row();
33	if (!$link->query("SET GLOBAL max_allowed_packet=(2<<29)")) {
34		if (1227 == mysqli_errno($link)) {
35			/* [1227] Access denied; you need the SUPER privilege for this operation */
36			$cols = 10;
37		} else {
38			$cols = 10;
39			printf("[002] Failed to set max_allowed_packet the test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link));
40		}
41	}
42	mysqli_close($link);
43
44
45	if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
46		printf("Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
47			$host, $user, $db, $port, $socket);
48		exit(1);
49	}
50
51	if (!mysqli_query($link, 'DROP TABLE IF EXISTS test')) {
52		printf("Failed to drop old test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link));
53		exit(1);
54	}
55
56	$str = array();
57	for ($i = 1; $i <= $cols; $i++) {
58		$str[] ="a$i BLOB";
59	}
60	$link->query("CREATE TABLE test(" . implode(" , ", $str) . ") ENGINE=MyISAM");
61	if (mysqli_errno($link)) {
62		printf("Failed to create the test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link));
63		die("");
64	}
65	$stmt = $link->prepare("INSERT INTO test VALUES(".str_repeat("?, ", $cols-1) . "?)");
66	var_dump($stmt->id);
67	$s = str_repeat("a", 2 << 12);
68	$eval_str="\$stmt->bind_param(\"".str_repeat("s",$cols)."\", ";
69	for ($i = 1; $i < $cols; $i++) {
70		$eval_str.="\$s,";
71	}
72	$eval_str.="\$s";
73	$eval_str.=");";
74	eval($eval_str);
75	printf("executing\n");
76	if (!$stmt->execute()) {
77		printf("failed");
78		printf("Failed to execute: [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
79	} else {
80		var_dump(true);
81	}
82
83	mysqli_stmt_close($stmt);
84
85
86	if (!$link->query("SET GLOBAL max_allowed_packet=$old_max_allowed_packet")) {
87		if (1227 != mysqli_errno($link))
88			printf("Failed to set max_allowed_packet the test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link));
89	}
90
91	mysqli_close($link);
92
93	print "done!";
94?>
95--CLEAN--
96<?php
97	require_once("clean_table.inc");
98?>
99--EXPECTF--
100int(1)
101executing
102bool(true)
103done!
104