mysqli_connect_twice.phpt 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. --TEST--
  2. Calling connect() on an open connection to create a new connection
  3. --EXTENSIONS--
  4. mysqli
  5. --SKIPIF--
  6. <?php
  7. require_once('skipifconnectfailure.inc');
  8. ?>
  9. --FILE--
  10. <?php
  11. require_once("connect.inc");
  12. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  13. printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  14. $host, $user, $db, $port, $socket);
  15. if (!$thread_id = mysqli_thread_id($link))
  16. printf("[002] Cannot determine thread id, test will fail, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  17. if (true !== ($tmp = my_mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket)))
  18. printf("[003] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp);
  19. if (!is_int($new_thread_id = mysqli_thread_id($link)) || ($new_thread_id < 0))
  20. printf("[004] Expecting int/any got %s/%s\n", gettype($tmp), $tmp);
  21. if ($thread_id == $new_thread_id)
  22. printf("[005] Expecting new connection and new thread id. Old thread id %d, new thread id %d\n", $thread_id, $new_thread_id);
  23. if (!($res = mysqli_query($link, "SELECT 'ok' AS it_works")) ||
  24. !($row = mysqli_fetch_assoc($res)))
  25. printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  26. var_dump($row);
  27. mysqli_free_result($res);
  28. mysqli_close($link);
  29. if (!$link = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
  30. printf("[007] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  31. $host, $user, $db, $port, $socket);
  32. if (!$thread_id = $link->thread_id)
  33. printf("[008] Cannot determine thread id, test will fail, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  34. if (true !== ($tmp = $link->real_connect($host, $user, $passwd, $db, $port, $socket)))
  35. printf("[009] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp);
  36. if (!is_int($new_thread_id = $link->thread_id) || ($new_thread_id < 0))
  37. printf("[010] Expecting int/any got %s/%s\n", gettype($tmp), $tmp);
  38. if ($thread_id == $new_thread_id)
  39. printf("[011] Expecting new connection and new thread id. Old thread id %d, new thread id %d\n", $thread_id, $new_thread_id);
  40. if (!($res = $link->query("SELECT 'works also with oo' AS syntax")) ||
  41. !($row = $res->fetch_assoc()))
  42. printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  43. var_dump($row);
  44. mysqli_free_result($res);
  45. mysqli_close($link);
  46. if (true !== ($tmp = $link->connect($host, $user, $passwd, $db, $port, $socket)))
  47. printf("[013] Expecting true got %s/%s\n", gettype($tmp), $tmp);
  48. if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  49. printf("[014] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  50. $host, $user, $db, $port, $socket);
  51. if (true !== ($tmp = $link->connect($host, $user, $passwd, $db, $port, $socket)))
  52. printf("[015] Expecting NULL got %s/%s\n", gettype($tmp), $tmp);
  53. print "done!";
  54. ?>
  55. --EXPECT--
  56. array(1) {
  57. ["it_works"]=>
  58. string(2) "ok"
  59. }
  60. array(1) {
  61. ["syntax"]=>
  62. string(18) "works also with oo"
  63. }
  64. done!