mysqli_insert_id_variation.phpt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. --TEST--
  2. Checking last_insert_id after different operations
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifconnectfailure.inc');
  7. ?>
  8. --FILE--
  9. <?php
  10. require_once("connect.inc");
  11. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  12. printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  13. $host, $user, $db, $port, $socket);
  14. $link->query("DROP TABLE IF EXISTS test_insert_id_var");
  15. $link->query("CREATE TABLE test_insert_id_var (id INT auto_increment, PRIMARY KEY (id))");
  16. $link->query("INSERT INTO test_insert_id_var VALUES (null)");
  17. $i = $link->insert_id;
  18. if (!$i) {
  19. printf("[001] Got no valid insert id: %s", var_export($i, true));
  20. die();
  21. }
  22. $link->options(MYSQLI_OPT_LOCAL_INFILE, false);
  23. if ($i != $link->insert_id || $i != mysqli_insert_id($link)) {
  24. printf("[002] mysqli_option changes insert_id: %s", var_export($link->insert_id, true));
  25. die();
  26. }
  27. /*
  28. $link->dump_debug_info();
  29. if ($i != $link->insert_id || $i != mysqli_insert_id($link)) {
  30. printf("[003] mysqli_debug_info changes insert_id: %s", var_export($link->insert_id, true));
  31. die();
  32. }
  33. */
  34. $link->stat();
  35. if ($i != $link->insert_id || $i != mysqli_insert_id($link)) {
  36. printf("[004] mysqli_stat changes insert_id: %s", var_export($link->insert_id, true));
  37. die();
  38. }
  39. /*$link->kill($link->thread_id);
  40. if ($i != $link->insert_id || $i != mysqli_insert_id($link)) {
  41. printf("[005] mysqli_kill changes insert_id: %s", var_export($link->insert_id, true));
  42. die();
  43. }*/
  44. $link->ping();
  45. if ($i != $link->insert_id || $i != mysqli_insert_id($link)) {
  46. printf("[006] mysqli_ping changes insert_id: %s", var_export($link->insert_id, true));
  47. die();
  48. }
  49. /*
  50. mysqlnd resets the IDE to 0
  51. libmysql doesn't
  52. $link->change_user ($user, $passwd, $db);
  53. if (0 != $link->insert_id || 0 != mysqli_insert_id($link)) {
  54. printf("[007] mysqli_change_user changes insert_id: %s", var_export($link->insert_id, true));
  55. die();
  56. }
  57. */
  58. $stmt = $link->prepare("SELECT 1");
  59. if ($i != $link->insert_id || $i != mysqli_insert_id($link)) {
  60. printf("[008a] mysqli_prepare changes insert_id: %s", var_export($link->insert_id, true));
  61. die();
  62. }
  63. echo mysqli_error($link);
  64. if (0 != $stmt->insert_id || 0 != mysqli_stmt_insert_id($stmt)) {
  65. printf("[008b] mysqli_stmt doesn't initialise insert_id: %s", var_export($stmt->insert_id, true));
  66. die();
  67. }
  68. unset($stmt);
  69. if ($i != $link->insert_id || $i != mysqli_insert_id($link)) {
  70. printf("[009] stmt free changes insert_id: %s", var_export($link->insert_id, true));
  71. die();
  72. }
  73. $link->query("DROP TABLE IF EXISTS test_insert_id_var");
  74. echo "DONE";
  75. ?>
  76. --CLEAN--
  77. <?php
  78. require_once("connect.inc");
  79. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  80. printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  81. if (!mysqli_query($link, "DROP TABLE IF EXISTS test_insert_id_var"))
  82. printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  83. mysqli_close($link);
  84. ?>
  85. --EXPECTF--
  86. DONE