PageRenderTime 35ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/facebook/hiphop-php
PHP | 59 lines | 45 code | 13 blank | 1 comment | 12 complexity | b54bb891b7ea0206d545cc4e71f80607 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 "connect.inc";
  3. include 'setupdefault.inc';
  4. $tmp = NULL;
  5. $link = NULL;
  6. if (0 !== ($tmp = @mysql_insert_id()))
  7. printf("[001] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
  8. if (NULL !== ($tmp = @mysql_insert_id($link)))
  9. printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  10. if (!is_null($tmp = @mysql_insert_id($link, 'too many args')))
  11. printf("[002a] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  12. require('table.inc');
  13. if (0 !== ($tmp = mysql_insert_id($link)))
  14. printf("[003] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
  15. if (!$res = mysql_query("SELECT id, label FROM test ORDER BY id LIMIT 1", $link)) {
  16. printf("[004] [%d] %s\n", mysql_errno($link), mysql_error($link));
  17. }
  18. if (0 !== ($tmp = mysql_insert_id($link)))
  19. printf("[005] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
  20. mysql_free_result($res);
  21. // no auto_increment column
  22. if (!$res = mysql_query("INSERT INTO test(id, label) VALUES (100, 'a')", $link)) {
  23. printf("[006] [%d] %s\n", mysql_errno($link), mysql_error($link));
  24. }
  25. if (0 !== ($tmp = mysql_insert_id($link)))
  26. printf("[007] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
  27. if (!$res = mysql_query("ALTER TABLE test MODIFY id INT NOT NULL AUTO_INCREMENT", $link)) {
  28. printf("[008] [%d] %s\n", mysql_errno($link), mysql_error($link));
  29. }
  30. if (!$res = mysql_query("INSERT INTO test(label) VALUES ('a')", $link)) {
  31. printf("[009] [%d] %s\n", mysql_errno($link), mysql_error($link));
  32. }
  33. if (0 === ($tmp = mysql_insert_id($link)))
  34. printf("[010] Expecting int/not zero, got %s/%s\n", gettype($tmp), $tmp);
  35. if ($tmp !== ($tmp2 = mysql_insert_id()))
  36. printf("[011] Expecting %s/%s, got %s/%s\n",
  37. gettype($tmp), $tmp,
  38. gettype($tmp2), $tmp2);
  39. mysql_close($link);
  40. var_dump(mysql_insert_id($link));
  41. print "done!";
  42. ?>
  43. <?php error_reporting(0); ?>
  44. <?php
  45. require_once("clean_table.inc");
  46. ?>