mysqli_data_seek.phpt 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. --TEST--
  2. mysqli_data_seek()
  3. --EXTENSIONS--
  4. mysqli
  5. --SKIPIF--
  6. <?php
  7. require_once('skipifconnectfailure.inc');
  8. ?>
  9. --FILE--
  10. <?php
  11. require_once("connect.inc");
  12. require('table.inc');
  13. if (!$res = mysqli_query($link, 'SELECT * FROM test ORDER BY id LIMIT 4', MYSQLI_STORE_RESULT))
  14. printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  15. if (true !== ($tmp = mysqli_data_seek($res, 3)))
  16. printf("[005] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  17. $row = mysqli_fetch_assoc($res);
  18. if (4 != $row['id'])
  19. printf("[006] Expecting record 4/d, got record %s/%s\n", $row['id'], $row['label']);
  20. if (true !== ($tmp = mysqli_data_seek($res, 0)))
  21. printf("[007] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  22. $row = mysqli_fetch_assoc($res);
  23. if (1 != $row['id'])
  24. printf("[008] Expecting record 1/a, got record %s/%s\n", $row['id'], $row['label']);
  25. if (false !== ($tmp = mysqli_data_seek($res, 4)))
  26. printf("[009] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  27. try {
  28. mysqli_data_seek($res, -1);
  29. } catch (\ValueError $e) {
  30. echo $e->getMessage() . \PHP_EOL;
  31. }
  32. mysqli_free_result($res);
  33. if (!$res = mysqli_query($link, 'SELECT * FROM test ORDER BY id', MYSQLI_USE_RESULT))
  34. printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  35. try {
  36. var_dump(mysqli_data_seek($res, 3));
  37. } catch (\Error $e) {
  38. echo $e->getMessage() . \PHP_EOL;
  39. }
  40. mysqli_free_result($res);
  41. try {
  42. mysqli_data_seek($res, 1);
  43. } catch (Error $exception) {
  44. echo $exception->getMessage() . "\n";
  45. }
  46. mysqli_close($link);
  47. print "done!";
  48. ?>
  49. --CLEAN--
  50. <?php
  51. require_once("clean_table.inc");
  52. ?>
  53. --EXPECT--
  54. mysqli_data_seek(): Argument #2 ($offset) must be greater than or equal to 0
  55. mysqli_data_seek() cannot be used in MYSQLI_USE_RESULT mode
  56. mysqli_result object is already closed
  57. done!