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

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

http://github.com/facebook/hiphop-php
PHP | 110 lines | 80 code | 29 blank | 1 comment | 29 complexity | 4662380b7256171a0962afbfb67c8606 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("[004] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  7. $host, $user, $db, $port, $socket);
  8. if (0 !== ($tmp = mysqli_affected_rows($link)))
  9. printf("[005] Expecting int/0, got %s/%s. [%d] %s\n",
  10. gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
  11. if (!mysqli_query($link, 'DROP TABLE IF EXISTS test_mysqli_affected_rows_table_1'))
  12. printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  13. if (!mysqli_query($link, 'CREATE TABLE test_mysqli_affected_rows_table_1(id INT, label CHAR(1), PRIMARY KEY(id)) ENGINE = ' . $engine))
  14. printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  15. if (!mysqli_query($link, "INSERT INTO test_mysqli_affected_rows_table_1(id, label) VALUES (1, 'a')"))
  16. printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  17. if (1 !== ($tmp = mysqli_affected_rows($link)))
  18. printf("[010] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
  19. // ignore INSERT error, NOTE: command line returns 0, affected_rows returns -1 as documented
  20. mysqli_query($link, "INSERT INTO test_mysqli_affected_rows_table_1(id, label) VALUES (1, 'a')");
  21. if (-1 !== ($tmp = mysqli_affected_rows($link)))
  22. printf("[011] Expecting int/-1, got %s/%s\n", gettype($tmp), $tmp);
  23. if (!mysqli_query($link, "INSERT INTO test_mysqli_affected_rows_table_1(id, label) VALUES (1, 'a') ON DUPLICATE KEY UPDATE id = 4"))
  24. printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  25. if (2 !== ($tmp = mysqli_affected_rows($link)))
  26. printf("[013] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp);
  27. if (!mysqli_query($link, "INSERT INTO test_mysqli_affected_rows_table_1(id, label) VALUES (2, 'b'), (3, 'c')"))
  28. printf("[014] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  29. if (2 !== ($tmp = mysqli_affected_rows($link)))
  30. printf("[015] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp);
  31. if (!mysqli_query($link, "INSERT IGNORE INTO test_mysqli_affected_rows_table_1(id, label) VALUES (1, 'a')")) {
  32. printf("[016] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  33. }
  34. if (1 !== ($tmp = mysqli_affected_rows($link)))
  35. printf("[017] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
  36. if (!mysqli_query($link, "INSERT INTO test_mysqli_affected_rows_table_1(id, label) SELECT id + 10, label FROM test_mysqli_affected_rows_table_1"))
  37. printf("[018] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  38. if (4 !== ($tmp = mysqli_affected_rows($link)))
  39. printf("[019] Expecting int/4, got %s/%s\n", gettype($tmp), $tmp);
  40. if (!mysqli_query($link, "REPLACE INTO test_mysqli_affected_rows_table_1(id, label) values (4, 'd')"))
  41. printf("[020] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  42. if (2 !== ($tmp = mysqli_affected_rows($link)))
  43. printf("[021] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp);
  44. if (!mysqli_query($link, "REPLACE INTO test_mysqli_affected_rows_table_1(id, label) values (5, 'e')"))
  45. printf("[022] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  46. if (1 !== ($tmp = mysqli_affected_rows($link)))
  47. printf("[023] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
  48. if (!mysqli_query($link, "UPDATE test_mysqli_affected_rows_table_1 SET label = 'a' WHERE id = 2"))
  49. printf("[024] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  50. if (1 !== ($tmp = mysqli_affected_rows($link)))
  51. printf("[025] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
  52. $charsets = array('utf8');
  53. foreach ($charsets as $k => $charset) {
  54. if (!($res = mysqli_query($link, sprintf("SHOW CHARACTER SET LIKE '%s'", $charset))))
  55. continue;
  56. mysqli_free_result($res);
  57. if (true !== ($tmp = mysqli_set_charset($link, $charset)))
  58. printf("[026] Expecting boolean/true got %s/%s\n",
  59. gettype($tmp), $tmp);
  60. if (0 !== ($tmp = mysqli_affected_rows($link)))
  61. printf("[027] Expecting int/0 got %s/%s\n", gettype($tmp), $tmp);
  62. }
  63. if (!mysqli_query($link, "UPDATE test_mysqli_affected_rows_table_1 SET label = 'a' WHERE id = 2")) {
  64. printf("[028] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  65. }
  66. if (0 !== ($tmp = mysqli_affected_rows($link)))
  67. printf("[029] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
  68. if (!mysqli_query($link, "UPDATE test_mysqli_affected_rows_table_1 SET label = 'a' WHERE id = 100")) {
  69. printf("[030] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  70. }
  71. if (0 !== ($tmp = mysqli_affected_rows($link)))
  72. printf("[031] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
  73. if (!mysqli_query($link, 'DROP TABLE IF EXISTS test_mysqli_affected_rows_table_1'))
  74. printf("[032] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  75. mysqli_close($link);
  76. print "done!";
  77. ?>
  78. <?php error_reporting(0); ?>
  79. <?php
  80. $test_table_name = 'test_mysqli_affected_rows_table_1'; require_once("clean_table.inc");
  81. ?>