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

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

http://github.com/facebook/hiphop-php
PHP | 115 lines | 80 code | 34 blank | 1 comment | 31 complexity | 7771ef0d140b54306b63f6cc0db002d6 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. include_once('setupdefault.inc');
  4. $tmp = NULL;
  5. $link = NULL;
  6. if (0 !== ($tmp = @mysql_affected_rows()))
  7. printf("[001] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
  8. if (null !== ($tmp = @mysql_affected_rows($link)))
  9. printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  10. if (!is_null($tmp = @mysql_affected_rows($link, $link)))
  11. printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  12. if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket))
  13. printf("[004] 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 (-1 !== ($tmp = mysql_affected_rows($link)))
  16. printf("[005] Expecting int/-1, got %s/%s. [%d] %s\n",
  17. gettype($tmp), $tmp, mysql_errno($link), mysql_error($link));
  18. if (!mysql_query('DROP TABLE IF EXISTS test', $link))
  19. printf("[006] [%d] %s\n", mysql_errno($link), mysql_error($link));
  20. if (!mysql_query('CREATE TABLE test(id INT, label CHAR(1), PRIMARY KEY(id)) ENGINE = ' . $engine, $link))
  21. printf("[007] [%d] %s\n", mysql_errno($link), mysql_error($link));
  22. if (!mysql_query("INSERT INTO test(id, label) VALUES (1, 'a')", $link))
  23. printf("[008] [%d] %s\n", mysql_errno($link), mysql_error($link));
  24. if (1 !== ($tmp = mysql_affected_rows($link)))
  25. printf("[010] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
  26. // ignore INSERT error, NOTE: command line returns 0, affected_rows returns -1 as documented
  27. @mysql_query("INSERT INTO test(id, label) VALUES (1, 'a')", $link);
  28. if (-1 !== ($tmp = mysql_affected_rows($link)))
  29. printf("[011] Expecting int/-1, got %s/%s\n", gettype($tmp), $tmp);
  30. if (!mysql_query("INSERT INTO test(id, label) VALUES (1, 'a') ON DUPLICATE KEY UPDATE id = 4", $link))
  31. printf("[012] [%d] %s\n", mysql_errno($link), mysql_error($link));
  32. if (2 !== ($tmp = mysql_affected_rows($link)))
  33. printf("[013] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp);
  34. if (!mysql_query("INSERT INTO test(id, label) VALUES (2, 'b'), (3, 'c')", $link))
  35. printf("[014] [%d] %s\n", mysql_errno($link), mysql_error($link));
  36. if (2 !== ($tmp = mysql_affected_rows($link)))
  37. printf("[015] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp);
  38. if (!mysql_query("INSERT IGNORE INTO test(id, label) VALUES (1, 'a')", $link)) {
  39. printf("[016] [%d] %s\n", mysql_errno($link), mysql_error($link));
  40. }
  41. if (1 !== ($tmp = mysql_affected_rows($link)))
  42. printf("[017] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
  43. if (!mysql_query("INSERT INTO test(id, label) SELECT id + 10, label FROM test", $link))
  44. printf("[018] [%d] %s\n", mysql_errno($link), mysql_error($link));
  45. if (4 !== ($tmp = mysql_affected_rows($link)))
  46. printf("[019] Expecting int/4, got %s/%s\n", gettype($tmp), $tmp);
  47. if (!mysql_query("REPLACE INTO test(id, label) values (4, 'd')", $link))
  48. printf("[020] [%d] %s\n", mysql_errno($link), mysql_error($link));
  49. if (2 !== ($tmp = mysql_affected_rows($link)))
  50. printf("[021] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp);
  51. if (!mysql_query("REPLACE INTO test(id, label) values (5, 'e')", $link))
  52. printf("[022] [%d] %s\n", mysql_errno($link), mysql_error($link));
  53. if (1 !== ($tmp = mysql_affected_rows($link)))
  54. printf("[023] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
  55. if (!mysql_query("UPDATE test SET label = 'a' WHERE id = 2", $link))
  56. printf("[024] [%d] %s\n", mysql_errno($link), mysql_error($link));
  57. if (1 !== ($tmp = mysql_affected_rows($link)))
  58. printf("[025] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
  59. if (!mysql_query("UPDATE test SET label = 'a' WHERE id = 2", $link)) {
  60. printf("[025] [%d] %s\n", mysql_errno($link), mysql_error($link));
  61. }
  62. if (0 !== ($tmp = mysql_affected_rows($link)))
  63. printf("[026] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
  64. if (!mysql_query("UPDATE test SET label = 'a' WHERE id = 100", $link)) {
  65. printf("[025] [%d] %s\n", mysql_errno($link), mysql_error($link));
  66. }
  67. if (0 !== ($tmp = mysql_affected_rows($link)))
  68. printf("[026] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
  69. if (0 !== ($tmp = mysql_affected_rows()))
  70. printf("[027] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
  71. if (!mysql_query('DROP TABLE IF EXISTS test', $link))
  72. printf("[028] [%d] %s\n", mysql_errno($link), mysql_error($link));
  73. mysql_close($link);
  74. if (false !== ($tmp = @mysql_affected_rows($link)))
  75. printf("[029] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  76. print "done!";
  77. ?>
  78. <?php error_reporting(0); ?>
  79. <?php
  80. require_once("clean_table.inc");
  81. ?>