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