Get mysqli_stmt_send_long_data to work
[hiphop-php.git] / hphp / test / zend / good / ext / mysqli / tests / mysqli_stmt_send_long_data_packet_size_libmysql.php
blob28b4b9e5f6e460fe0cea8af3b3ea6c5ae30e46e0
1 <?php
2 $test_table_name = 'test_mysqli_stmt_send_long_data_packet_size_libmysql_table_1'; require('table.inc');
4 if (!$stmt = mysqli_stmt_init($link))
5 printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
7 if (!mysqli_query($link, "DROP TABLE IF EXISTS test"))
8 printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
10 if (!mysqli_query($link, sprintf("CREATE TABLE test(id INT NOT NULL AUTO_INCREMENT, label LONGBLOB, PRIMARY KEY(id)) ENGINE = %s", $engine)))
11 printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
13 if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(id, label) VALUES (?, ?)"))
14 printf("[004] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
16 $id = null;
17 $label = null;
18 if (!mysqli_stmt_bind_param($stmt, "ib", $id, $label))
19 printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
21 if (!$res = mysqli_query($link, "SHOW VARIABLES LIKE 'max_allowed_packet'"))
22 printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
24 if (!$row = mysqli_fetch_assoc($res))
25 printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
27 mysqli_free_result($res);
29 if (0 === ($max_allowed_packet = (int)$row['Value']))
30 printf("[008] Cannot determine max_allowed_packet size and/or bogus max_allowed_packet setting used.\n");
32 // let's ignore upper limits for LONGBLOB (2^32) ...
33 // maximum packet size up to which we test is 10M
34 $tmp = '';
35 $blob = '';
36 for ($i = 0; $i < 1024; $i++) {
37 $tmp .= 'a';
40 $limit = min(floor($max_allowed_packet / 1024 / 2), 10240);
41 for ($i = 0; $i < $limit; $i++)
42 $blob .= $tmp;
44 assert(strlen($blob) <= $max_allowed_packet);
46 if (true != ($tmp = mysqli_stmt_send_long_data($stmt, 1, $blob)))
47 printf("[009] Expecting boolean/true, got %s/%s. [%d] %s\n",
48 gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
50 $id = 1;
51 if (true !== mysqli_stmt_execute($stmt))
52 printf("[010] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
55 TODO - we skip this part of the test for now, because of bugs.mysql.com/26824
56 if (floor($max_allowed_packet / 1024 / 2) <= 10240) {
57 // test with a blob smaller than 10M allows us to test
58 // for too long packages without wasting too much memory
59 $limit = $max_allowed_packet - strlen($blob) + 1;
60 $blob2 = $blob;
61 for ($i = 0; $i < $limit; $i++)
62 $blob2 .= 'b';
64 assert(strlen($blob2) > $max_allowed_packet);
66 if (true != ($tmp = mysqli_stmt_send_long_data($stmt, 1, $blob2)))
67 printf("[011] Expecting boolean/false, got %s/%s. [%d] %s\n",
68 gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
70 $id = 2;
71 if (false !== ($tmp = mysqli_stmt_execute($stmt)))
72 printf("[012] Expecting boolean/false, got %s/%s, [%d] %s\n",
73 gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
76 mysqli_stmt_close($stmt);
77 mysqli_close($link);
79 print "done!";
81 <?php
82 $test_table_name = 'test_mysqli_stmt_send_long_data_packet_size_libmysql_table_1'; require_once("clean_table.inc");