test.inc 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /* This file is part of PHP test framework for ext/sybase_ct
  3. *
  4. * $Id$
  5. */
  6. // Change if needed
  7. define('HOST', getenv('PHP_SYBASE_HOST'));
  8. define('USER', getenv('PHP_SYBASE_USER'));
  9. define('PASSWORD', getenv('PHP_SYBASE_PASS'));
  10. define('TEMPDB', 'tempdb');
  11. // {{{ bool sybase_msg_handler(int msgnumber, int severity, int state, int line, string text)
  12. // Handles server messages
  13. function sybase_msg_handler($msgnumber, $severity, $state, $line, $text) {
  14. printf(
  15. "*** Caught Sybase Server Message #%d [Severity %d, state %d] at line %d\n '%s'\n",
  16. $msgnumber,
  17. $severity,
  18. $state,
  19. $line,
  20. chop($text)
  21. );
  22. }
  23. // }}}
  24. // {{{ public class sybase
  25. class sybase {
  26. // {{{ public static bool static_handler(int msgnumber, int severity, int state, int line, string text)
  27. // Handles server messages
  28. static function static_handler($msgnumber, $severity, $state, $line, $text) {
  29. return sybase_msg_handler($msgnumber, $severity, $state, $line, $text);
  30. }
  31. // }}}
  32. // {{{ public bool static_handler(int msgnumber, int severity, int state, int line, string text)
  33. // Handles server messages
  34. function handler($msgnumber, $severity, $state, $line, $text) {
  35. return sybase_msg_handler($msgnumber, $severity, $state, $line, $text);
  36. }
  37. // }}}
  38. }
  39. // }}}
  40. // {{{ void sybase_set_messagehandler_ex(string handler)
  41. // Sets the sybase message handler and dumps the result
  42. function sybase_set_messagehandler_ex($handler) {
  43. var_dump(sybase_set_message_handler($handler));
  44. }
  45. // {{{ resource sybase_connect_ex(string charset= NULL, string appname= NULL, bool new= FALSE)
  46. // Connect to the sybase server using the defines HOST, USER and PASSWORD
  47. function sybase_connect_ex($charset= NULL, $appname= NULL, $new= FALSE) {
  48. sybase_min_server_severity(11); // Suppress "changed database context"
  49. if (!($db= sybase_connect(HOST, USER, PASSWORD, $charset ? $charset : 'iso_1', $appname, $new))) {
  50. die('Connect to '.USER.'@'.HOST.' failed (using password: '.(PASSWORD ? 'yes' : 'no').')');
  51. }
  52. return $db;
  53. }
  54. // }}}
  55. // {{{ void sybase_select_ex(resource dbh, string query)
  56. // Returns all fetched rows from an SQL query
  57. function sybase_select_ex($dbh, $query) {
  58. printf(">>> Query: %s\n", $query);
  59. $h= sybase_query($query, $dbh);
  60. printf("<<< Return: %s\n", gettype($h));
  61. flush();
  62. if (!is_resource($h)) return $h;
  63. $return= array();
  64. while ($row= sybase_fetch_assoc($h)) {
  65. $return[]= $row;
  66. }
  67. return $return;
  68. }
  69. // {{{ mixed sybase_select_single(resource dbh, string query)
  70. // Fires an SQL query and returns the first value from the first row
  71. function sybase_select_single($dbh, $query) {
  72. $a = sybase_fetch_row(sybase_query($query, $dbh));
  73. return array_shift($a);
  74. }
  75. // }}}
  76. ?>