Back to index

php5  5.3.10
test.inc
Go to the documentation of this file.
00001 <?php
00002 /* This file is part of PHP test framework for ext/sybase_ct
00003  *
00004  * $Id: test.inc 268732 2008-11-10 11:00:48Z thekid $ 
00005  */
00006 
00007   // Change if needed
00008   define('HOST',     getenv('PHP_SYBASE_HOST'));
00009   define('USER',     getenv('PHP_SYBASE_USER'));
00010   define('PASSWORD', getenv('PHP_SYBASE_PASS'));
00011   define('TEMPDB',   'tempdb');
00012 
00013   // {{{ bool sybase_msg_handler(int msgnumber, int severity, int state, int line, string text)
00014   //     Handles server messages
00015   function sybase_msg_handler($msgnumber, $severity, $state, $line, $text) {
00016     printf(
00017       "*** Caught Sybase Server Message #%d [Severity %d, state %d] at line %d\n    '%s'\n",
00018       $msgnumber,
00019       $severity,
00020       $state,
00021       $line,
00022       chop($text)
00023     );
00024   }
00025   // }}}
00026 
00027   // {{{ public class sybase
00028   class sybase {
00029   
00030     // {{{ public static bool static_handler(int msgnumber, int severity, int state, int line, string text)
00031     //     Handles server messages
00032     static function static_handler($msgnumber, $severity, $state, $line, $text) {
00033       return sybase_msg_handler($msgnumber, $severity, $state, $line, $text);
00034     }
00035     // }}}
00036 
00037     // {{{ public bool static_handler(int msgnumber, int severity, int state, int line, string text)
00038     //     Handles server messages
00039     function handler($msgnumber, $severity, $state, $line, $text) { 
00040       return sybase_msg_handler($msgnumber, $severity, $state, $line, $text);
00041     }
00042     // }}}
00043   }
00044   // }}}
00045 
00046   // {{{ void sybase_set_messagehandler_ex(string handler)
00047   //     Sets the sybase message handler and dumps the result
00048   function sybase_set_messagehandler_ex($handler) {
00049     var_dump(sybase_set_message_handler($handler));
00050   }
00051   
00052   // {{{ resource sybase_connect_ex(string charset= NULL, string appname= NULL, bool new= FALSE)
00053   //     Connect to the sybase server using the defines HOST, USER and PASSWORD
00054   function sybase_connect_ex($charset= NULL, $appname= NULL, $new= FALSE) {
00055     sybase_min_server_severity(11);       // Suppress "changed database context"
00056     if (!($db= sybase_connect(HOST, USER, PASSWORD, $charset ? $charset : 'iso_1', $appname, $new))) {
00057       die('Connect to '.USER.'@'.HOST.' failed (using password: '.(PASSWORD ? 'yes' : 'no').')');
00058     }
00059     return $db;
00060   }
00061   // }}}
00062 
00063   // {{{ void sybase_select_ex(resource dbh, string query)
00064   //     Returns all fetched rows from an SQL query
00065   function sybase_select_ex($dbh, $query) {
00066     printf(">>> Query: %s\n", $query);
00067     $h= sybase_query($query, $dbh);
00068     printf("<<< Return: %s\n", gettype($h));
00069     flush();
00070     if (!is_resource($h)) return $h;
00071 
00072     $return= array();
00073     while ($row= sybase_fetch_assoc($h)) {
00074       $return[]= $row;
00075     }
00076     return $return;
00077   }
00078   
00079   // {{{ mixed sybase_select_single(resource dbh, string query)
00080   //     Fires an SQL query and returns the first value from the first row
00081   function sybase_select_single($dbh, $query) {
00082     $a = sybase_fetch_row(sybase_query($query, $dbh));
00083     return array_shift($a);
00084   }
00085   // }}}
00086 ?>