"Fossies" - the Fresh Open Source Software Archive

Member "mythreads/lib/phplib/db_sybase.inc" (29 Mar 2001, 3505 Bytes) of package /linux/privat/mythreads-links_1.2.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) fasm source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "db_sybase.inc" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.2.0_vs_1.2.1.

    1 <?php
    2 /*
    3  * Session Management for PHP3
    4  *
    5  * Copyright (c) 1998-2000 NetUSE AG
    6  *                    Boris Erdmann, Kristian Koehntopp
    7  *
    8  * Adapted from db_mysql.inc by Sascha Schumann <sascha@schumann.cx>
    9  *
   10  * metadata() contributed by Adelino Monteiro <adelino@infologia.pt>
   11  *
   12  * $Id: db_sybase.inc,v 1.1 2001-03-29 21:51:52 ldrolez Exp $
   13  *
   14  */ 
   15 
   16 class DB_Sql {
   17   var $Host     = "";
   18   var $Database = "";
   19   var $User     = "";
   20   var $Password = "";
   21 
   22   var $Link_ID  = 0;
   23   var $Query_ID = 0;
   24   var $Record   = array();
   25   var $Row;
   26 
   27   var $Auto_Free = 0;     ## Set this to 1 for automatic sybase_free_result()
   28 
   29   /* public: constructor */
   30   function DB_Sql($query = "") {
   31       $this->query($query);
   32   }
   33 
   34   function connect() {
   35     if ( 0 == $this->Link_ID ) {
   36       $this->Link_ID=sybase_pconnect($this->Host,$this->User,$this->Password);
   37       if (!$this->Link_ID) {
   38         $this->halt("Link-ID == false, pconnect failed");
   39       }
   40       if(!sybase_select_db($this->Database, $this->Link_ID)) {
   41         $this->halt("cannot use database ".$this->Database);
   42       }
   43     }
   44   }
   45 
   46   function query($Query_String) {
   47 
   48 
   49     /* No empty queries, please, since PHP4 chokes on them. */
   50     if ($Query_String == "")
   51       /* The empty query string is passed on from the constructor,
   52        * when calling the class without a query, e.g. in situations
   53        * like these: '$db = new DB_Sql_Subclass;'
   54        */
   55       return 0;
   56 
   57     $this->connect();
   58 
   59 #   printf("Debug: query = %s<br>\n", $Query_String);
   60 
   61     $this->Query_ID = sybase_query($Query_String,$this->Link_ID);
   62     $this->Row   = 0;
   63     if (!$this->Query_ID) {
   64       $this->halt("Invalid SQL: ".$Query_String);
   65     }
   66 
   67     return $this->Query_ID;
   68   }
   69 
   70   function next_record() {
   71     $this->Record = sybase_fetch_array($this->Query_ID);
   72     $this->Row   += 1;
   73 
   74     $stat = is_array($this->Record);
   75     if (!$stat && $this->Auto_Free) {
   76       sybase_free_result($this->Query_ID);
   77       $this->Query_ID = 0;
   78     }
   79     return $stat;
   80   }
   81 
   82   function seek($pos) {
   83     $status = sybase_data_seek($this->Query_ID, $pos);
   84     if ($status)
   85       $this->Row = $pos;
   86     return;
   87   }
   88 
   89   function metadata($table) {
   90       $count = 0;
   91       $id    = 0;
   92       $res   = array();
   93 
   94       $this->connect(); 
   95       $result = $this->query("exec sp_columns $table");
   96       if ($result < 0) {
   97           $this->Errno = 1;
   98           $this->Error = "Metadata query failed";
   99           $this->halt("Metadata query failed.");
  100       }
  101       $count = sybase_num_rows($result);
  102 
  103       for ($i=0; $i<$count; $i++) {
  104           $res[$i]["table"] = $table ;
  105           $res[$i]["name"]  = sybase_result ($result, $i, "COLUMN_NAME");
  106           $res[$i]["type"]  = sybase_result ($result, $i, "TYPE_NAME");
  107           $res[$i]["len"]   = sybase_result ($result, $i, "LENGTH");
  108           $res[$i]["position"] = sybase_result ($result, $i, "ORDINAL_POSITION");
  109           $res[$i]["flags"] = sybase_result ($result, $i, "REMARKS");
  110 
  111       }
  112   }
  113 
  114   function affected_rows() {
  115     return sybase_affected_rows($this->Query_ID);
  116   }
  117 
  118   function num_rows() {
  119     return sybase_num_rows($this->Query_ID);
  120   }
  121 
  122   function num_fields() {
  123     return sybase_num_fields($this->Query_ID);
  124   }
  125 
  126   function nf() {
  127     return $this->num_rows();
  128   }
  129 
  130   function np() {
  131     print $this->num_rows();
  132   }
  133 
  134   function f($Name) {
  135     return $this->Record[$Name];
  136   }
  137 
  138   function p($Name) {
  139     print $this->Record[$Name];
  140   }
  141   
  142   function halt($msg) {
  143     printf("</td></tr></table><b>Database error:</b> %s<br>\n", $msg);
  144     printf("<b>Sybase Error</b><br>\n");
  145     die("Session halted.");
  146   }
  147 }
  148 ?>