mysqli_stmt_bind_limits.phpt 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. --TEST--
  2. Bind limits
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifemb.inc');
  7. require_once('skipifconnectfailure.inc');
  8. ?>
  9. --FILE--
  10. <?php
  11. require_once("connect.inc");
  12. function bind_many($offset, $link, $num_params, $rows, $eval = true) {
  13. $drop = "DROP TABLE IF EXISTS test";
  14. $create = "CREATE TABLE test(id INT AUTO_INCREMENT PRIMARY KEY, ";
  15. $insert = "INSERT INTO test";
  16. $columns = "";
  17. $values = "";
  18. $stmt_params = "";
  19. $params = array();
  20. for ($i = 0; $i < $num_params; $i++) {
  21. $create .= "col" . $i . " INT, ";
  22. $columns .= "col" . $i . ", ";
  23. $values .= "?, ";
  24. $stmt_params .= '$params[' . $i . '], ';
  25. for ($j = 0; $j < $rows; $j++)
  26. $params[($j * $rows) + $i] = $i;
  27. }
  28. $create = substr($create, 0, -2) . ")";
  29. $stmt_types = str_repeat("i", $num_params * $rows);
  30. $stmt_params = substr(str_repeat($stmt_params, $rows), 0, -2);
  31. $values = substr($values, 0, -2);
  32. $insert .= "(" . substr($columns, 0, -2) . ") VALUES ";
  33. $insert .= substr(str_repeat("(" . $values . "), ", $rows), 0, -2);
  34. $stmt_bind_param = 'return mysqli_stmt_bind_param($stmt, "' . $stmt_types . '", ' . $stmt_params . ');';
  35. printf("Testing %d columns with %d rows...\n", $num_params, $rows);
  36. if (!$link->query($drop) || !$link->query($create)) {
  37. printf("[%03d + 01] [%d] %s\n", $offset, $link->errno, $link->error);
  38. return false;
  39. }
  40. printf("... table created\n");
  41. if (!$stmt = $link->prepare($insert)) {
  42. printf("[%03d + 02] [%d] %s\n", $offset, $link->errno, $link->error);
  43. return false;
  44. }
  45. if ($stmt->param_count != $num_params * $rows) {
  46. printf("[%03d + 03] Parameter count should be %d but got %d\n", $offset, $num_params * $rows, $stmt->param_count);
  47. return false;
  48. }
  49. printf("... statement with %d parameters prepared\n", $stmt->param_count);
  50. if ($eval) {
  51. if (!eval($stmt_bind_param)) {
  52. printf("[%03d + 03] [%d] %s\n", $offset, $stmt->errno, $stmt->error);
  53. return false;
  54. }
  55. } else {
  56. $param_ref = array($stmt_types);
  57. for ($i = 0; $i < $rows; $i++)
  58. for ($j = 0; $j < $num_params; $j++)
  59. $param_ref[] = &$params[($i * $rows) + $j];
  60. if (!call_user_func_array(array($stmt, 'bind_param'), $param_ref)) {
  61. printf("[%03d + 03] [%d] %s\n", $offset, $stmt->errno, $stmt->error);
  62. return false;
  63. }
  64. }
  65. if ($stmt->param_count != $num_params * $rows) {
  66. printf("[%03d + 03] Parameter count should be %d but got %d\n", $offset, $num_params * $rows, $stmt->param_count);
  67. return false;
  68. }
  69. if (!$stmt->execute()) {
  70. printf("[%03d + 04] [%d] %s\n", $offset, $stmt->errno, $stmt->error);
  71. return false;
  72. }
  73. printf("Statement done\n");
  74. $stmt->close();
  75. if (!($res = $link->query("SELECT * FROM test"))) {
  76. printf("[%03d + 05] [%d] %s\n", $offset, $link->errno, $link->error);
  77. return false;
  78. }
  79. $row = $res->fetch_row();
  80. $res->close();
  81. for ($i = 0; $i < $num_params; $i++) {
  82. if ($row[$i + 1] != $i) {
  83. printf("[%03d + 06] [%d] %s\n", $offset, $link->errno, $link->error);
  84. }
  85. }
  86. return true;
  87. }
  88. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
  89. printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  90. $host, $user, $db, $port, $socket);
  91. }
  92. var_dump(bind_many(10, $link, 273, 240, true));
  93. var_dump(bind_many(20, $link, 273, 240, false));
  94. mysqli_close($link);
  95. print "done!";
  96. ?>
  97. --CLEAN--
  98. <?php
  99. require_once("clean_table.inc");
  100. ?>
  101. --EXPECTF--
  102. Testing 273 columns with 240 rows...
  103. ... table created
  104. ... statement with 65520 parameters prepared
  105. Statement done
  106. bool(true)
  107. Testing 273 columns with 240 rows...
  108. ... table created
  109. ... statement with 65520 parameters prepared
  110. Statement done
  111. bool(true)
  112. done!