xref: /php-src/ext/mysqli/tests/bug35759.phpt (revision a21edc52)
1--TEST--
2Bug #35759 (mysqli_stmt_bind_result() makes huge allocation when column empty)
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once 'skipifconnectfailure.inc';
8?>
9--FILE--
10<?php
11
12    require_once 'connect.inc';
13    $col_num= 1000;
14
15    $mysql = new mysqli($host, $user, $passwd, $db, $port, $socket);
16    $mysql->query("DROP TABLE IF EXISTS test");
17    $create = "CREATE TABLE test (a0 MEDIUMBLOB NOT NULL DEFAULT ''";
18    $i= 0;
19    while (++$i < $col_num) {
20        $create .= ", a$i MEDIUMBLOB NOT NULL DEFAULT ''";
21    }
22    $create .= ") ENGINE=MyISAM"; // doesn't work with InnoDB, which is default in 5.5
23
24    if (!$mysql->query($create)) {
25        if (1101 == $mysql->errno) {
26            /* SQL strict mode - [1101] BLOB/TEXT column 'a0' can't have a default value */
27            print "done!";
28            exit(0);
29        }
30        printf("[001] [%d] %s\n", $mysql->errno, $mysql->error);
31    }
32
33    if (!$mysql->query("INSERT INTO test (a0) VALUES ('')"))
34        printf("[002] [%d] %s\n", $mysql->errno, $mysql->error);
35
36    $stmt = $mysql->prepare("SELECT * FROM test");
37    if ($stmt) {
38
39        $stmt->execute();
40        $stmt->store_result();
41        for ($i = 0; $i < $col_num; $i++) {
42            $params[] = &$col_num;
43        }
44        call_user_func_array(array($stmt, "bind_result"), $params);
45        $stmt->fetch();
46
47        $stmt->close();
48    } else {
49        printf("[003] [%d] %s\n", $mysql->errno, $mysql->error);
50    }
51
52    $mysql->close();
53
54    echo "done!";
55?>
56--CLEAN--
57<?php require 'clean_table.inc'; ?>
58--EXPECT--
59done!
60