mysqli_data_seek_oo.phpt 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. --TEST--
  2. mysqli_result->data_seek()
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifemb.inc');
  7. require_once('skipifconnectfailure.inc');
  8. ?>
  9. --FILE--
  10. <?php
  11. require_once("connect.inc");
  12. $tmp = NULL;
  13. $link = NULL;
  14. require('table.inc');
  15. if (!$mysqli = new mysqli($host, $user, $passwd, $db, $port, $socket))
  16. printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  17. $host, $user, $db, $port, $socket);
  18. $res = new mysqli_result($mysqli);
  19. if (NULL !== ($tmp = @$res->data_seek(0)))
  20. printf("[002] Expecting NULL/NULL, got %s/%s\n", gettype($tmp), $tmp);
  21. if (!$res = $mysqli->query('SELECT * FROM test ORDER BY id LIMIT 4', MYSQLI_STORE_RESULT))
  22. printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  23. if (NULL !== ($tmp = @$res->data_seek()))
  24. printf("[004] Expecting NULL/NULL, got %s/%s\n", gettype($tmp), $tmp);
  25. if (NULL !== ($tmp = @$res->data_seek($link)))
  26. printf("[005] Expecting NULL/NULL, got %s/%s\n", gettype($tmp), $tmp);
  27. if (NULL !== ($tmp = @$res->data_seek($link, $link)))
  28. printf("[006] Expecting NULL/NULL, got %s/%s\n", gettype($tmp), $tmp);
  29. if (true !== ($tmp = $res->data_seek(3)))
  30. printf("[007] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  31. $row = $res->fetch_assoc();
  32. if (4 != $row['id'])
  33. printf("[008] Expecting record 4/d, got record %s/%s\n", $row['id'], $row['label']);
  34. if (true !== ($tmp = $res->data_seek(0)))
  35. printf("[009] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  36. $row = $res->fetch_assoc();
  37. if (1 != $row['id'])
  38. printf("[010] Expecting record 1/a, got record %s/%s\n", $row['id'], $row['label']);
  39. if (false !== ($tmp = $res->data_seek(4)))
  40. printf("[011] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  41. if (false !== ($tmp = $res->data_seek(-1)))
  42. printf("[012] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  43. $res->free_result();
  44. if (!$res = $mysqli->query('SELECT * FROM test ORDER BY id', MYSQLI_USE_RESULT))
  45. printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  46. if (false !== ($tmp = $res->data_seek(3)))
  47. printf("[014] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  48. $res->free_result();
  49. if (NULL !== ($tmp = $res->data_seek(1)))
  50. printf("[015] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  51. $mysqli->close();
  52. print "done!";
  53. ?>
  54. --CLEAN--
  55. <?php
  56. require_once("clean_table.inc");
  57. ?>
  58. --EXPECTF--
  59. Warning: mysqli_result::data_seek(): Function cannot be used with MYSQL_USE_RESULT in %s on line %d
  60. Warning: mysqli_result::data_seek(): Couldn't fetch mysqli_result in %s on line %d
  61. done!