1--TEST-- 2mysqli_stmt_send_long_data() - exceed packet size, mysqlnd 3--EXTENSIONS-- 4mysqli 5--SKIPIF-- 6<?php 7require_once 'skipifconnectfailure.inc'; 8?> 9--FILE-- 10<?php 11 require 'table.inc'; 12 13 if (!$stmt = mysqli_stmt_init($link)) 14 printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 15 16 if (!mysqli_query($link, "DROP TABLE IF EXISTS test")) 17 printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 18 19 if (!mysqli_query($link, sprintf("CREATE TABLE test(id INT NOT NULL AUTO_INCREMENT, label LONGBLOB, PRIMARY KEY(id)) ENGINE = %s", $engine))) 20 printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 21 22 if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(id, label) VALUES (?, ?)")) 23 printf("[004] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 24 25 $id = null; 26 $label = null; 27 if (!mysqli_stmt_bind_param($stmt, "ib", $id, $label)) 28 printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 29 30 if (!$res = mysqli_query($link, "SHOW VARIABLES LIKE 'max_allowed_packet'")) 31 printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 32 33 if (!$row = mysqli_fetch_assoc($res)) 34 printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 35 36 mysqli_free_result($res); 37 38 if (0 === ($max_allowed_packet = (int)$row['Value'])) 39 printf("[008] Cannot determine max_allowed_packet size and/or bogus max_allowed_packet setting used.\n"); 40 41 // let's ignore upper limits for LONGBLOB (2^32) ... 42 // maximum packet size up to which we test is 10M 43 $tmp = str_repeat('a', 1024); 44 45 $limit = min(floor($max_allowed_packet / 1024 / 2), 10240); 46 $blob = str_repeat($tmp, $limit); 47 48 assert(strlen($blob) <= $max_allowed_packet); 49 50 if (true !== ($tmp = mysqli_stmt_send_long_data($stmt, 1, $blob))) 51 printf("[009] Expecting boolean/true, got %s/%s. [%d] %s\n", 52 gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 53 54 $id = 1; 55 if (true !== mysqli_stmt_execute($stmt)) 56 printf("[010] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 57 58 /* 59 TODO - we skip this because of the open bug http://bugs.mysql.com/bug.php?id=26824 60 It would always fail. 61 62 This should be added to the EXPECTF, if you reactivate the test 63Warning: mysqli_stmt_send_long_data(): Skipped %d bytes. Last command STMT_SEND_LONG_DATA hasn't consumed all the output from the server in %s on line %d 64 65Warning: mysqli_stmt_send_long_data(): There was an error while sending long data. Probably max_allowed_packet_size is smaller than the data. You have to increase it or send smaller chunks of data. Answer was %d bytes long. in %s on line %d 66 67 68 69 if (floor($max_allowed_packet / 1024 / 2) <= 10240) { 70 // test with a blob smaller than 10M allows us to test 71 // for too long packages without wasting too much memory 72 $limit = $max_allowed_packet - strlen($blob) + 1; 73 $blob2 = $blob; 74 $blob2 .= str_repeat('b', $limit); 75 76 assert(strlen($blob2) > $max_allowed_packet); 77 78 if (false !== ($tmp = mysqli_stmt_send_long_data($stmt, 1, $blob2))) 79 printf("[011] Expecting boolean/false, got %s/%s. [%d] %s\n", 80 gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 81 82 $id = 2; 83 if (false !== ($tmp = mysqli_stmt_execute($stmt))) 84 printf("[012] Expecting boolean/false, got %s/%s, [%d] %s\n", 85 gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 86 } 87 */ 88 mysqli_stmt_close($stmt); 89 mysqli_close($link); 90 91 print "done!"; 92?> 93--CLEAN-- 94<?php 95 require_once 'clean_table.inc'; 96?> 97--EXPECT-- 98done! 99