PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/facebook/hiphop-php
PHP | 97 lines | 79 code | 16 blank | 2 comment | 29 complexity | 026625e9fe8cd2460c012bef043e6aa3 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. include_once "connect.inc";
  3. $tmp = NULL;
  4. $link = NULL;
  5. // mysql_connect ( [string server [, string username [, string password [, bool new_link [, int client_flags]]]]] )
  6. if (NULL !== ($tmp = @mysql_connect($link, $link, $link, $link, $link, $link)))
  7. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  8. $myhost = (is_null($socket)) ? ((is_null($port)) ? $host : $host . ':' . $port) : $host . ':' . $socket;
  9. if (!$link = mysql_connect($myhost, $user, $passwd, true))
  10. printf("[002] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  11. $host, $myhost, $user, $db, $port, $socket);
  12. mysql_close($link);
  13. if (!$link = mysql_connect($myhost, $user, $passwd, true))
  14. printf("[003] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  15. $host, $myhost, $user, $db, $port, $socket);
  16. mysql_close();
  17. if ($link = mysql_connect($myhost, $user . 'unknown_really', $passwd . 'non_empty', true))
  18. printf("[004] Can connect to the server using host=%s/%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n",
  19. $host, $myhost, $user . 'unknown_really', $db, $port, $socket);
  20. if (false !== $link)
  21. printf("[005] Expecting boolean/false, got %s/%s\n", gettype($link), $link);
  22. // Run the following tests without an anoynmous MySQL user and use a password for the test user!
  23. ini_set('mysql.default_socket', $socket);
  24. if (!is_null($socket)) {
  25. if (!is_resource($link = mysql_connect($host, $user, $passwd, true))) {
  26. printf("[006] Usage of mysql.default_socket failed\n");
  27. } else {
  28. mysql_close($link);
  29. }
  30. }
  31. if (!ini_get('sql.safe_mode')) {
  32. ini_set('mysql.default_port', $port);
  33. if (!is_null($port)) {
  34. if (!is_resource($link = mysql_connect($host, $user, $passwd, true))) {
  35. printf("[007] Usage of mysql.default_port failed\n");
  36. } else {
  37. mysql_close($link);
  38. }
  39. }
  40. ini_set('mysql.default_password', $passwd);
  41. if (!is_resource($link = mysql_connect($myhost, $user))) {
  42. printf("[008] Usage of mysql.default_password failed\n");
  43. } else {
  44. mysql_close($link);
  45. }
  46. ini_set('mysql.default_user', $user);
  47. if (!is_resource($link = mysql_connect($myhost))) {
  48. printf("[009] Usage of mysql.default_user failed\n");
  49. } else {
  50. mysql_close($link);
  51. }
  52. ini_set('mysql.default_host', $myhost);
  53. if (!is_resource($link = mysql_connect())) {
  54. printf("[010] Usage of mysql.default_host failed\n") ;
  55. } else {
  56. mysql_close($link);
  57. }
  58. if (!is_resource($link = mysql_connect()) || !is_resource($link2 = mysql_connect())) {
  59. printf("[011] Usage of mysql.default_host failed\n") ;
  60. } else {
  61. mysql_close();
  62. mysql_close($link2);
  63. }
  64. if (!stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'netware')) {
  65. ini_set('mysql.default_port', -1);
  66. if (putenv(sprintf('MYSQL_TCP_PORT=%d', $port))) {
  67. if (!is_resource($link = mysql_connect())) {
  68. printf("[012] Usage of env MYSQL_TCP_PORT failed\n") ;
  69. } else {
  70. mysql_close($link);
  71. }
  72. } else if (putenv(sprintf('MYSQL_TCP_PORT=%d', $port + 1))) {
  73. if (!is_resource($link = mysql_connect())) {
  74. printf("[013] Usage of env MYSQL_TCP_PORT=%d should have failed\n", $port + 1) ;
  75. mysql_close($link);
  76. }
  77. }
  78. }
  79. }
  80. print "done!";
  81. ?>