bug48754.phpt 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. --TEST--
  2. Bug #48754 (mysql_close() crash php when no handle specified)
  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. function my_mysql_pconnect($host, $user, $passwd, $db, $port, $socket) {
  12. if ($socket)
  13. $host = sprintf("%s:%s", $host, $socket);
  14. else if ($port)
  15. $host = sprintf("%s:%s", $host, $port);
  16. if (!$link = mysql_pconnect($host, $user, $passwd, true)) {
  17. printf("[000-a] Cannot connect using host '%s', user '%s', password '****', [%d] %s\n",
  18. $host, $user, $passwd,
  19. mysql_errno(), mysql_error());
  20. return false;
  21. }
  22. return $link;
  23. }
  24. echo "Explicit connection on close\n";
  25. $link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket);
  26. $link1_thread_id = mysql_thread_id($link);
  27. $default1_thread_id = mysql_thread_id();
  28. echo 'Expect same thread id for $link and default conn: ';
  29. var_dump($link1_thread_id == $default1_thread_id);
  30. var_dump($link);
  31. mysql_close($link);
  32. var_dump($link);
  33. // we sohuld have no default link anymore
  34. mysql_close();
  35. echo "\nClosing default link\n";
  36. $link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket);
  37. $link2_thread_id = mysql_thread_id($link);
  38. $default2_thread_id = mysql_thread_id();
  39. echo 'Expect same thread id for $link and default conn but not the previous: ';
  40. var_dump($link1_thread_id == $default1_thread_id && $link1_thread_id != $link2_thread_id);
  41. var_dump($link);
  42. mysql_close();
  43. var_dump($link);
  44. mysql_close($link);
  45. var_dump($link);
  46. echo "\nExplicit resource and pconnect\n";
  47. $link = my_mysql_pconnect($host, $user, $passwd, $db, $port, $socket);
  48. var_dump($link);
  49. mysql_close($link);
  50. var_dump($link);
  51. // we sohuld have no default link
  52. mysql_close();
  53. echo "\nDefault link and pconnect\n";
  54. $link = my_mysql_pconnect($host, $user, $passwd, $db, $port, $socket);
  55. var_dump($link);
  56. mysql_close();
  57. var_dump($link);
  58. mysql_close($link);
  59. var_dump($link);
  60. ?>
  61. --EXPECTF--
  62. Explicit connection on close
  63. Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
  64. Expect same thread id for $link and default conn: bool(true)
  65. resource(%d) of type (mysql link)
  66. resource(%d) of type (Unknown)
  67. Warning: mysql_close(): no MySQL-Link resource supplied in %s on line %d
  68. Closing default link
  69. Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
  70. Expect same thread id for $link and default conn but not the previous: bool(true)
  71. resource(%d) of type (mysql link)
  72. resource(%d) of type (mysql link)
  73. resource(%d) of type (Unknown)
  74. Explicit resource and pconnect
  75. Deprecated: mysql_pconnect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
  76. resource(%d) of type (mysql link persistent)
  77. resource(%d) of type (Unknown)
  78. Warning: mysql_close(): no MySQL-Link resource supplied in %s on line %d
  79. Default link and pconnect
  80. Deprecated: mysql_pconnect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
  81. resource(%d) of type (mysql link persistent)
  82. resource(%d) of type (mysql link persistent)
  83. resource(%d) of type (Unknown)