"Fossies" - the Fresh Open Source Software Archive

Member "mythreads/lib/phplib/db_mssql.inc" (29 Mar 2001, 3974 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_mssql.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  * (C) Copyright 1998 Cameron Taggart (cameront@wolfenet.com)
    6  *        Modified by Guarneri carmelo (carmelo@melting-soft.com)
    7  *    Modified by Cameron Just     (C.Just@its.uq.edu.au)    
    8  *
    9  * $Id: db_mssql.inc,v 1.1 2001-03-29 21:51:52 ldrolez Exp $
   10  */ 
   11 # echo "<BR>This is using the MSSQL class<BR>";
   12 
   13 class DB_Sql {
   14   var $Host     = "";
   15   var $Database = "";
   16   var $User     = "";
   17   var $Password = "";
   18 
   19   var $Link_ID  = 0;
   20   var $Query_ID = 0;
   21   var $Record   = array();
   22   var $Row      = 0;
   23   
   24   var $Errno    = 0;
   25   var $Error    = "";
   26 
   27   var $Auto_Free = 0;     ## set this to 1 to automatically free results
   28   
   29   
   30   /* public: constructor */
   31   function DB_Sql($query = "") {
   32       $this->query($query);
   33   }
   34 
   35   function connect() {
   36     if ( 0 == $this->Link_ID ) {
   37       $this->Link_ID=mssql_pconnect($this->Host, $this->User, $this->Password);
   38       if (!$this->Link_ID)
   39         $this->halt("Link-ID == false, mssql_pconnect failed");
   40       else
   41         mssql_select_db($this->Database, $this->Link_ID);
   42     }
   43   }
   44   function free_result(){
   45       mssql_free_result($this->Query_ID);
   46     $this->Query_ID = 0;
   47   }
   48   
   49   function query($Query_String) 
   50   {
   51     
   52     /* No empty queries, please, since PHP4 chokes on them. */
   53     if ($Query_String == "")
   54       /* The empty query string is passed on from the constructor,
   55        * when calling the class without a query, e.g. in situations
   56        * like these: '$db = new DB_Sql_Subclass;'
   57        */
   58       return 0;
   59 
   60     if (!$this->Link_ID)
   61         $this->connect();
   62     
   63 #   printf("<br>Debug: query = %s<br>\n", $Query_String);
   64     
   65     $this->Query_ID = mssql_query($Query_String, $this->Link_ID);
   66     $this->Row = 0;
   67     if (!$this->Query_ID) {
   68       $this->Errno = 1;
   69       $this->Error = "General Error (The MSSQL interface cannot return detailed error messages).";
   70       $this->halt("Invalid SQL: ".$Query_String);
   71     }
   72     return $this->Query_ID;
   73   }
   74   
   75   function next_record() {
   76     
   77     if ($this->Record = mssql_fetch_row($this->Query_ID)) {
   78       // add to Record[<key>]
   79       $count = mssql_num_fields($this->Query_ID);
   80       for ($i=0; $i<$count; $i++){
   81         $fieldinfo = mssql_fetch_field($this->Query_ID,$i);
   82         $this->Record[strtolower($fieldinfo->name)] = $this->Record[$i];
   83       }
   84       $this->Row += 1;
   85       $stat = 1;
   86     } else {
   87       if ($this->Auto_Free) {
   88             $this->free_result();
   89         }
   90       $stat = 0;
   91     }
   92     return $stat;
   93   }
   94   
   95   function seek($pos) {
   96         mssql_data_seek($this->Query_ID,$pos);
   97     $this->Row = $pos;
   98   }
   99 
  100   function metadata($table) {
  101     $count = 0;
  102     $id    = 0;
  103     $res   = array();
  104 
  105     $this->connect();
  106     $id = mssql_query("select * from $table", $this->Link_ID);
  107     if (!$id) {
  108       $this->Errno = 1;
  109       $this->Error = "General Error (The MSSQL interface cannot return detailed error messages).";
  110       $this->halt("Metadata query failed.");
  111     }
  112     $count = mssql_num_fields($id);
  113     
  114     for ($i=0; $i<$count; $i++) {
  115         $info = mssql_fetch_field($id, $i);
  116       $res[$i]["table"] = $table;
  117       $res[$i]["name"]  = $info["name"];
  118       $res[$i]["len"]   = $info["max_length"];
  119       $res[$i]["flags"] = $info["numeric"];
  120     }
  121     $this->free_result();
  122     return $res;
  123   }
  124   
  125   function affected_rows() {
  126     return mssql_affected_rows($this->Query_ID);
  127   }
  128   
  129   function num_rows() {
  130     return mssql_num_rows($this->Query_ID);
  131   }
  132   
  133   function num_fields() {
  134     return mssql_num_fields($this->Query_ID);
  135   }
  136 
  137   function nf() {
  138     return $this->num_rows();
  139   }
  140   
  141   function np() {
  142     print $this->num_rows();
  143   }
  144   
  145   function f($Field_Name) {
  146     return $this->Record[strtolower($Field_Name)];
  147   }
  148   
  149   function p($Field_Name) {
  150     print $this->f($Field_Name);
  151   }
  152   
  153   function halt($msg) {
  154     printf("</td></tr></table><b>Database error:</b> %s<br>\n", $msg);
  155     printf("<b>MSSQL Error</b>: %s (%s)<br>\n",
  156       $this->Errno,
  157       $this->Error);
  158     die("Session halted.");
  159   }
  160 }
  161 ?>