phpBMS

Show
Ignore:
Timestamp:
04/07/09 11:44:18 (3 years ago)
Author:
nate
Message:
  • Merged Nathan branch back into trunk.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/phpbms/include/db.php

    r427 r485  
    1 <?php  
     1<?php 
    22/* 
    33 $Rev: 249 $ | $LastChangedBy: brieb $ 
     
    4141                //we may want to do more than connect via mysql; 
    4242                var $type="mysql"; 
    43                                  
     43 
    4444                // mysql vars; 
    4545                var $db_link; 
     
    4949                var $dbpass; 
    5050                var $pconnect=true; 
    51                  
     51 
    5252                var $showError=false; 
    5353                var $logError=true; 
    5454                var $stopOnError=true; 
    5555                var $errorFormat="xhtml"; 
    56                  
     56 
    5757                var $error = NULL; 
    58                                  
     58 
    5959                function db($connect = true, $hostname = NULL, $schema = NULL, $user = NULL, $pass = NULL, $pconnect = NULL, $type = "mysql"){ 
    60                          
     60 
    6161                        if($type!="mysql") 
    6262                        $this->type=$type; 
     
    6969                                        if($hostname!=NULL) 
    7070                                                $this->hostname = $hostname; 
    71                                          
     71 
    7272                                        if(defined("MYSQL_DATABASE")) 
    7373                                                $this->schema = MYSQL_DATABASE; 
    7474                                        if($schema!=NULL) 
    7575                                                $this->schema = $schema; 
    76                  
     76 
    7777                                        if(defined("MYSQL_USER")) 
    7878                                                $this->dbuser = MYSQL_USER; 
    7979                                        if($schema!=NULL) 
    8080                                                $this->dbuser = $user; 
    81                  
     81 
    8282                                        if(defined("MYSQL_USERPASS")) 
    8383                                                $this->dbpass = MYSQL_USERPASS; 
    8484                                        if($schema!=NULL) 
    8585                                                $this->dbpass = $pass; 
    86                  
     86 
    8787                                        if(defined("MYSQL_PCONNECT")) 
    8888                                                $this->pconnect = MYSQL_PCONNECT; 
    8989                                        if($pconnect!=NULL) 
    9090                                                $this->pconnect = $pconnect; 
    91                                 break;                           
     91                                break; 
    9292                        } 
    93                                                  
     93 
    9494                        if($connect){ 
    9595                                if($this->connect()){ 
     
    9797                                                return $this->db_link; 
    9898                                        else 
    99                                                 return false;                            
     99                                                return false; 
    100100                                } else 
    101101                                        return false; 
     
    106106                function connect(){ 
    107107                        // This functions connects to the database.  It uses pconnect if the variable is set; 
    108                                                  
     108 
    109109                        if($this->pconnect) 
    110110                                $this->db_link = @ mysql_pconnect($this->hostname,$this->dbuser,$this->dbpass); 
    111111                        else 
    112112                                $this->db_link = @ mysql_connect($this->hostname,$this->dbuser,$this->dbpass); 
     113 
    113114                        if(!$this->db_link){ 
     115 
    114116                                $error = new appError(-400,"Could not connect to database server.\n\n".$this->getError(),"",$this->showError,$this->stopOnError,false,$this->errorFormat); 
    115117                                return false; 
    116                         } else                   
     118 
     119                        } else 
    117120                                return $this->db_link; 
    118                 } 
    119  
    120                  
     121 
     122                }//end function connect 
     123 
     124 
    121125                function selectSchema($schema=NULL){ 
    122126                        if($schema!=NULL) 
    123127                                $this->schema=$schema; 
    124                                  
     128 
    125129                        if(! @ mysql_select_db($this->schema,$this->db_link)){ 
    126                                 $error = new appError(-410,"Could not open schema ".$this->schema,"",$this->showError,$this->stopOnError,false,$this->errorFormat);      
     130                                $error = new appError(-410,"Could not open schema ".$this->schema,"",$this->showError,$this->stopOnError,false,$this->errorFormat); 
    127131                                return false; 
    128132                        } else 
    129                                 return true;                                                     
     133                                return true; 
    130134                } 
    131135 
     
    134138                        switch($this->type){ 
    135139                                case "mysql": 
    136                                         if(!isset($this->db_link))  
    137                                                 if(!$this->dataB()) die($this->error); 
     140                                        if(!isset($this->db_link)) 
     141                                                if(!$this->db()) die($this->error); 
    138142                                        $queryresult = @ mysql_query($sqlstatement,$this->db_link); 
    139143                                        if(!$queryresult){ 
     
    141145                                                $error = new appError(-420,$this->getError($this->db_link)."\n\nStatement: ".$sqlstatement,"",$this->showError,$this->stopOnError,$this->logError,$this->errorFormat); 
    142146                                                return false; 
    143                                         }                                        
    144                                 break; 
    145                         }//end case 
    146                          
     147                                        } 
     148                                break; 
     149                        }//end case 
     150 
    147151                        $this->error=NULL; 
    148152                        return $queryresult; 
     
    153157 
    154158                        switch($this->type){ 
    155                                 case "mysql":                    
     159                                case "mysql": 
    156160                                        @ mysql_query("SET NAMES ".$encoding, $this->db_link); 
    157161                                        break; 
    158                                          
     162 
    159163                        }//endswitch 
    160164 
     
    163167 
    164168                function getError($link = NULL){ 
    165                          
    166                         switch($this->type){ 
    167                                 case "mysql": 
    168                                         $thereturn = mysql_error($link); 
     169 
     170                        switch($this->type){ 
     171                                case "mysql": 
     172                                        if($link) 
     173                                                $thereturn = @ mysql_error($link); 
     174                                        else 
     175                                                $thereturn = @ mysql_error(); 
    169176                                break; 
    170177                        }//end switch --type-- 
    171                          
    172                         return $thereturn; 
    173                          
     178 
     179                        return $thereturn; 
     180 
    174181                }//end method --getError-- 
    175                  
     182 
    176183 
    177184                function numRows($queryresult){ 
     
    200207                }//end function 
    201208 
    202                  
     209 
    203210                function startTransaction(){ 
    204                          
    205                         switch($this->type){ 
    206                                  
     211 
     212                        switch($this->type){ 
     213 
    207214                                case "mysql": 
    208215                                        $this->query("START TRANSACTION;"); 
    209216                                break; 
    210                          
     217 
    211218                        }//end switch 
    212                          
     219 
    213220                }//end method --startTransaction-- 
    214                  
    215                  
     221 
     222 
    216223                function commitTransaction(){ 
    217                          
    218                         switch($this->type){ 
    219                                  
     224 
     225                        switch($this->type){ 
     226 
    220227                                case "mysql": 
    221228                                        $this->query("COMMIT;"); 
    222229                                break; 
    223                          
     230 
    224231                        }//end switch 
    225                          
     232 
    226233                }//end method --startTransaction-- 
    227                  
    228                  
     234 
     235 
    229236                function rollbackTransaction(){ 
    230                          
    231                         switch($this->type){ 
    232                                  
     237 
     238                        switch($this->type){ 
     239 
    233240                                case "mysql": 
    234241                                        $this->query("ROLLBACK;"); 
    235242                                break; 
    236                          
     243 
    237244                        }//end switch 
    238                          
     245 
    239246                }//end method --startTransaction-- 
    240                  
     247 
    241248 
    242249                function seek($queryresult,$rownum){ 
     
    278285                        return $thereturn; 
    279286                }//end function 
    280                  
    281                  
     287 
     288 
    282289                function tableInfo($tablename){ 
    283290                        //this function returns a multi-dimensional array describing the fields in a given table 
     
    291298                                                        $thereturn[$name]["type"] = @ mysql_field_type($queryresult,$offset); 
    292299                                                        $thereturn[$name]["length"] = mysql_field_len($queryresult,$offset); 
    293                                                         $thereturn[$name]["flags"] = mysql_field_flags($queryresult,$offset);                                                    
     300                                                        $thereturn[$name]["flags"] = mysql_field_flags($queryresult,$offset); 
    294301                                                } 
    295302                                        } 
     
    305312                                case "mysql": 
    306313                                        $thereturn = @ mysql_insert_id($this->db_link); 
    307                                 break;                   
     314                                break; 
    308315                        } 
    309                          
     316 
    310317                        return $thereturn; 
    311318                } 
    312                  
     319 
    313320                function affectedRows(){ 
    314321                        $thereturn = false; 
     
    316323                                case "mysql": 
    317324                                        $thereturn = @ mysql_affected_rows($this->db_link); 
    318                                 break;                   
     325                                break; 
    319326                        } 
    320                          
     327 
    321328                        return $thereturn; 
    322329                } 
    323                  
     330 
    324331}//end db class 
    325332?> 
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.