test_fetch_object.phpt 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. --TEST--
  2. Sybase-CT sybase_fetch_object
  3. --SKIPIF--
  4. <?php
  5. require('skipif.inc');
  6. ?>
  7. --FILE--
  8. <?php
  9. /* This file is part of PHP test framework for ext/sybase_ct
  10. *
  11. * $Id$
  12. */
  13. require('test.inc');
  14. // {{{ class article
  15. class article { }
  16. // }}}
  17. // {{{ resource fetch_object(resource db, [mixed arg= NULL])
  18. // Fetches a resultset and returns it as an object
  19. function fetch_object($db, $arg= NULL) {
  20. return sybase_fetch_object(sybase_query('select
  21. 1 as "id",
  22. "Hello" as "caption",
  23. "timm" as "author",
  24. getdate() as "lastchange"
  25. ', $db), $arg);
  26. }
  27. // }}}
  28. $db= sybase_connect_ex();
  29. // Test with stdClass
  30. var_export(fetch_object($db)); echo "\n";
  31. // Test with userland class
  32. var_export(fetch_object($db, 'article')); echo "\n";
  33. // Test with object
  34. var_export(fetch_object($db, new article())); echo "\n";
  35. // Test with non-existent class
  36. var_export(fetch_object($db, '***')); echo "\n";
  37. sybase_close($db);
  38. ?>
  39. --EXPECTF--
  40. stdClass::__set_state(array(
  41. 'id' => 1,
  42. 'caption' => 'Hello',
  43. 'author' => 'timm',
  44. 'lastchange' => '%s',
  45. ))
  46. article::__set_state(array(
  47. 'id' => 1,
  48. 'caption' => 'Hello',
  49. 'author' => 'timm',
  50. 'lastchange' => '%s',
  51. ))
  52. article::__set_state(array(
  53. 'id' => 1,
  54. 'caption' => 'Hello',
  55. 'author' => 'timm',
  56. 'lastchange' => '%s',
  57. ))
  58. Notice: sybase_fetch_object(): Sybase: Class *** has not been declared in %stest_fetch_object.php on line %d
  59. stdClass::__set_state(array(
  60. 'id' => 1,
  61. 'caption' => 'Hello',
  62. 'author' => 'timm',
  63. 'lastchange' => '%s',
  64. ))