PageRenderTime 43ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/hphp/test/zend/bad/ext/mysqli/tests/mysqli_get_warnings.php

http://github.com/facebook/hiphop-php
PHP | 136 lines | 96 code | 38 blank | 2 comment | 55 complexity | 4e9ca89b24f99fc5145c2cd34e5f4476 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. $tmp = NULL;
  4. $link = NULL;
  5. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
  6. printf("[003] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  7. }
  8. if (false !== ($tmp = mysqli_get_warnings($link))) {
  9. printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), (is_object($tmp) ? var_dump($tmp, true) : $tmp));
  10. }
  11. if (!mysqli_query($link, "DROP TABLE IF EXISTS test"))
  12. printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  13. if (!mysqli_query($link, "CREATE TABLE test (id SMALLINT)"))
  14. printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  15. if (!mysqli_query($link, "INSERT INTO test (id) VALUES (1000000)"))
  16. printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  17. if (!is_object($warning = mysqli_get_warnings($link)) || 'mysqli_warning' != get_class($warning)) {
  18. printf("[008] Expecting object/mysqli_warning, got %s/%s\n", gettype($tmp), (is_object($tmp) ? var_dump($tmp, true) : $tmp));
  19. }
  20. if (!method_exists($warning, 'next'))
  21. printf("[009] Borked object, method next is missing\n");
  22. $properties = array_merge(get_object_vars($warning), get_class_vars(get_class($warning)));
  23. if (!empty($properties))
  24. printf("[010] Properties have always been magic, hidden things - why are they visible now, a BC break...\n");
  25. if ((!is_string($warning->message)) || ('' == $warning->message)) /* NULL or not there at all */
  26. printf("[011] Expecting string/not empty, got %s/%s\n", gettype($warning->message), $warning->message);
  27. if ((!is_string($warning->sqlstate)) || ('' == $warning->sqlstate)) /* NULL or not there at all */
  28. printf("[012] Expecting string/not empty, got %s/%s\n", gettype($warning->sqlstate), $warning->sqlstate);
  29. if ((!is_int($warning->errno)) || (0 == $warning->errno)) /* NULL or not there at all */
  30. printf("[013] Expecting int/not 0, got %s/%s\n", gettype($warning->errno), $warning->errno);
  31. if (false !== ($tmp = $warning->next()))
  32. printf("[014] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  33. if (!mysqli_query($link, "INSERT INTO test (id) VALUES (1000000), (1000001)"))
  34. printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  35. if (($tmp = mysqli_warning_count($link)) !== 2)
  36. printf("[016] Expecting 2 warnings, got %d warnings", $tmp);
  37. if (!is_object($warning = mysqli_get_warnings($link)) || 'mysqli_warning' != get_class($warning)) {
  38. printf("[017] Expecting object/mysqli_warning, got %s/%s\n", gettype($tmp), (is_object($tmp) ? var_dump($tmp, true) : $tmp));
  39. }
  40. if (true !== ($tmp = $warning->next()))
  41. printf("[018] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  42. if (false !== ($tmp = $warning->next()))
  43. printf("[020] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  44. mysqli_close($link);
  45. if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
  46. printf("[021] Cannot create mysqli object: [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  47. if (!$mysqli->query("DROP TABLE IF EXISTS t1"))
  48. printf("[022] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  49. if (!$mysqli->query("CREATE TABLE t1 (a smallint)"))
  50. printf("[023] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  51. if (!is_object($warning = new mysqli_warning($mysqli)))
  52. printf("[024] Expecting object/mysqli_warning, got %s/%s", gettype($warning), $warning);
  53. if (!is_string($warning->message) || ('' == $warning->message))
  54. printf("[025] Expecting string, got %s/%s", gettype($warning->message), $warning->message);
  55. if (!$mysqli->query("DROP TABLE t1"))
  56. printf("[026] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  57. /* Yes, I really want to check if the object property is empty */
  58. if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
  59. printf("[027] Cannot create mysqli object: [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  60. $warning = new mysqli_warning($mysqli);
  61. if (false !== ($tmp = $warning->next()))
  62. printf("[028] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  63. if ('' != ($tmp = $warning->message))
  64. printf("[029] Expecting string/empty, got %s/%s\n", gettype($tmp), $tmp);
  65. if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
  66. printf("[030] Cannot create mysqli object: [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  67. if (!$mysqli->query("DROP TABLE IF EXISTS t1"))
  68. printf("[031] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  69. if (!$mysqli->query("CREATE TABLE t1 (a smallint)"))
  70. printf("[032] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  71. /* out of range, three warnings */
  72. if (!$mysqli->query("INSERT IGNORE INTO t1(a) VALUES (65536), (65536), (65536)"))
  73. printf("[033] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  74. $warning = new mysqli_warning($mysqli);
  75. $i = 1;
  76. while ($warning->next() && ('' != ($tmp = $warning->message))) {
  77. if ((version_compare(PHP_VERSION, '5.9.9', '>') == 1) && !is_unicode($tmp))
  78. printf("[033a] Warning should have been a unicode string, got %s/%s", gettype($tmp), $tmp);
  79. $i++;
  80. }
  81. if (3 != $i)
  82. printf("[034] Expecting three warnings, got %d warnings\n", $i);
  83. $stmt = mysqli_stmt_init();
  84. $warning = new mysqli_warning($stmt);
  85. if (false !== ($tmp = $warning->next()))
  86. printf("[035] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  87. print "done!";
  88. ?>
  89. <?php
  90. require_once("connect.inc");
  91. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  92. printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  93. if (!mysqli_query($link, "DROP TABLE IF EXISTS test"))
  94. printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  95. if (!mysqli_query($link, "DROP TABLE IF EXISTS t1"))
  96. printf("[c003] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  97. mysqli_close($link);
  98. ?>