PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/bad/ext/mysql/tests/mysql_max_persistent.php

http://github.com/facebook/hiphop-php
PHP | 60 lines | 43 code | 13 blank | 4 comment | 7 complexity | 44347add15315692001f845855a03d9f MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?php
  2. require_once('connect.inc');
  3. function my_connect($offset, $host, $user, $passwd, $db, $port, $socket) {
  4. if ($socket)
  5. $host = sprintf("%s:%s", $host, $socket);
  6. else if ($port)
  7. $host = sprintf("%s:%s", $host, $port);
  8. $link = mysql_pconnect($host, $user, $passwd);
  9. if (!$link) {
  10. printf("[%03d] Cannot connect using host '%s', user '%s', password '****', [%d] %s\n",
  11. $offset, $host, $user, $passwd,
  12. mysql_errno(), mysql_error());
  13. return false;
  14. }
  15. if (!mysql_select_db($db, $link))
  16. return false;
  17. return $link;
  18. }
  19. $links = array();
  20. // try to open 2 links
  21. $links[0] = my_connect(10, $host, $user, $passwd, $db, $port, $socket);
  22. $links[1] = my_connect(20, $host, 'pcontest', 'pcontest', $db, $port, $socket);
  23. if (false !== $links[1])
  24. printf("[030] Last connection should not have been allowed!\n");
  25. // free some links but let index 1 remain
  26. unset($links[1]);
  27. mysql_close($links[0]);
  28. unset($links[0]);
  29. // should be allowed -> only open connection
  30. $links[0] = my_connect(40, $host, $user, $passwd, $db, $port, $socket);
  31. var_dump($links);
  32. mysql_query('REVOKE ALL PRIVILEGES, GRANT OPTION FROM pcontest', $links[0]);
  33. mysql_query('DROP USER pcontest', $links[0]);
  34. mysql_close($links[0]);
  35. print "done!\n";
  36. ?>
  37. <?php
  38. // connect + select_db
  39. require_once("connect.inc");
  40. if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket)) {
  41. printf("[c001] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  42. $host, $myhost, $user, $db, $port, $socket);
  43. }
  44. @mysql_query('REVOKE ALL PRIVILEGES, GRANT OPTION FROM pcontest', $link);
  45. @mysql_query('DROP USER pcontest', $link);
  46. mysql_close($link);
  47. ?>