mysqli_kill.phpt 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. --TEST--
  2. mysqli_kill()
  3. --EXTENSIONS--
  4. mysqli
  5. --SKIPIF--
  6. <?php
  7. require_once('skipifconnectfailure.inc');
  8. ?>
  9. --FILE--
  10. <?php
  11. require_once("connect.inc");
  12. require('table.inc');
  13. try {
  14. mysqli_kill($link, 0);
  15. } catch (\ValueError $e) {
  16. echo $e->getMessage() . \PHP_EOL;
  17. }
  18. if (!$thread_id = mysqli_thread_id($link))
  19. printf("[004] Cannot determine thread id, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  20. $tmp = mysqli_kill($link, $thread_id);
  21. if (!is_bool($tmp))
  22. printf("[005] Expecting boolean/any, got %s/%s\n", gettype($tmp), $tmp);
  23. if ($res = mysqli_query($link, "SELECT id FROM test LIMIT 1"))
  24. pintf("[006] Expecting boolean/false, got %s/%s\n", gettype($res), $res);
  25. var_dump($error = mysqli_error($link));
  26. if (!is_string($error) || ('' === $error))
  27. printf("[007] Expecting string/any non empty, got %s/%s\n", gettype($error), $error);
  28. var_dump($res);
  29. var_dump($link);
  30. if ($IS_MYSQLND) {
  31. if ($link->info != 'Records: 6 Duplicates: 0 Warnings: 0') {
  32. printf("[008] mysqlnd used to be more verbose and used to support SELECT\n");
  33. }
  34. } else {
  35. if ($link->info != NULL) {
  36. printf("[008] Time for wonders - libmysql has started to support SELECT, change test\n");
  37. }
  38. }
  39. mysqli_close($link);
  40. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  41. printf("[010] Cannot connect, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  42. try {
  43. mysqli_kill($link, -1);
  44. } catch (\ValueError $e) {
  45. echo $e->getMessage() . \PHP_EOL;
  46. }
  47. if ((!$res = mysqli_query($link, "SELECT id FROM test LIMIT 1")) ||
  48. (!$tmp = mysqli_fetch_assoc($res))) {
  49. printf("[011] Connection should not be gone, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  50. }
  51. var_dump($tmp);
  52. mysqli_free_result($res);
  53. mysqli_close($link);
  54. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  55. printf("[012] Cannot connect, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  56. mysqli_change_user($link, "This might work if you accept anonymous users in your setup", "password", $db);
  57. try {
  58. mysqli_kill($link, -1);
  59. } catch (\ValueError $e) {
  60. echo $e->getMessage() . \PHP_EOL;
  61. }
  62. mysqli_close($link);
  63. print "done!";
  64. ?>
  65. --CLEAN--
  66. <?php
  67. require_once("clean_table.inc");
  68. ?>
  69. --EXPECTF--
  70. mysqli_kill(): Argument #2 ($process_id) must be greater than 0
  71. string(%d) "%s"
  72. bool(false)
  73. object(mysqli)#%d (%d) {
  74. ["affected_rows"]=>
  75. int(-1)
  76. ["client_info"]=>
  77. string(%d) "%s"
  78. ["client_version"]=>
  79. int(%d)
  80. ["connect_errno"]=>
  81. int(0)
  82. ["connect_error"]=>
  83. NULL
  84. ["errno"]=>
  85. int(%d)
  86. ["error"]=>
  87. string(%d) "%s"
  88. ["error_list"]=>
  89. array(1) {
  90. [0]=>
  91. array(3) {
  92. ["errno"]=>
  93. int(%d)
  94. ["sqlstate"]=>
  95. string(5) "%s"
  96. ["error"]=>
  97. string(%d) "%s"
  98. }
  99. }
  100. ["field_count"]=>
  101. int(0)
  102. ["host_info"]=>
  103. string(%d) "%s"
  104. ["info"]=>
  105. %s
  106. ["insert_id"]=>
  107. int(0)
  108. ["server_info"]=>
  109. string(%d) "%s"
  110. ["server_version"]=>
  111. int(%d)
  112. ["sqlstate"]=>
  113. string(5) "HY000"
  114. ["protocol_version"]=>
  115. int(10)
  116. ["thread_id"]=>
  117. int(%d)
  118. ["warning_count"]=>
  119. int(0)
  120. }
  121. mysqli_kill(): Argument #2 ($process_id) must be greater than 0
  122. array(1) {
  123. ["id"]=>
  124. string(1) "1"
  125. }
  126. mysqli_kill(): Argument #2 ($process_id) must be greater than 0
  127. done!