Advertisement
Guest User

Backup

a guest
Nov 14th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 22.76 KB | None | 0 0
  1. <?php
  2.  
  3.  if ($_SERVER['SERVER_NAME']!='www.autopostomineiro.com.br') {
  4.      
  5.      exit ();
  6.  }
  7.  
  8.  else if ($_SERVER['SERVER_NAME']!='autopostomineiro.com.br') {
  9.      
  10.      exit ();
  11.          
  12.  }
  13.  
  14. class DB
  15. {
  16.     private $link = null;
  17.     public $filter;
  18.     static $inst = null;
  19.     public static $counter = 0;
  20.    
  21.  
  22.     public function log_db_errors( $error, $query )
  23.     {
  24.         $message = '<p>Errinho '. date('Y-m-d H:i:s').':</p>';
  25.         $message .= '<p>Query: '. htmlentities( $query ).'<br />';
  26.         $message .= 'Error: ' . $error;
  27.         $message .= '</p>';
  28.  
  29.         if( defined( 'SEND_ERRORS_TO' ) )
  30.         {
  31.             $headers  = 'MIME-Version: 1.0' . "\r\n";
  32.             $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  33.             $headers .= 'To: Admin <'.SEND_ERRORS_TO.'>' . "\r\n";
  34.             $headers .= 'From: AutopostoMineiro <system@'.$_SERVER['SERVER_NAME'].'.com>' . "\r\n";
  35.  
  36.             mail( SEND_ERRORS_TO, 'Database Error', $message, $headers );  
  37.         }
  38.         else
  39.         {
  40.             trigger_error( $message );
  41.         }
  42.  
  43.         if( !defined( 'DISPLAY_DEBUG' ) || ( defined( 'DISPLAY_DEBUG' ) && DISPLAY_DEBUG ) )
  44.         {
  45.             echo $message;  
  46.         }
  47.     }
  48.    
  49.    
  50.     public function __construct()
  51.     {
  52.         mb_internal_encoding( 'UTF-8' );
  53.         mb_regex_encoding( 'UTF-8' );
  54.         mysqli_report( MYSQLI_REPORT_STRICT );
  55.         try {
  56.             $this->link = new mysqli( DB_HOST, DB_USER, DB_PASS, DB_NAME );
  57.             $this->link->set_charset( "utf8" );
  58.         } catch ( Exception $e ) {
  59.             die( 'Unable to connect to database' );
  60.         }
  61.     }
  62.  
  63.     public function __destruct()
  64.     {
  65.         if( $this->link)
  66.         {
  67.             $this->disconnect();
  68.         }
  69.     }
  70.  
  71.  
  72.     /**
  73.      * Sanitize user data
  74.      *
  75.      * Example usage:
  76.      * $user_name = $database->filter( $_POST['user_name'] );
  77.      *
  78.      * Or to filter an entire array:
  79.      * $data = array( 'name' => $_POST['name'], 'email' => 'email@address.com' );
  80.      * $data = $database->filter( $data );
  81.      *
  82.      * @access public
  83.      * @param mixed $data
  84.      * @return mixed $data
  85.      */
  86.      public function filter( $data )
  87.      {
  88.          if( !is_array( $data ) )
  89.          {
  90.              $data = $this->link->real_escape_string( $data );
  91.              $data = trim( htmlentities( $data, ENT_QUOTES, 'UTF-8', false ) );
  92.          }
  93.          else
  94.          {
  95.              //Self call function to sanitize array data
  96.              $data = array_map( array( $this, 'filter' ), $data );
  97.          }
  98.          return $data;
  99.      }
  100.      
  101.      
  102.      /**
  103.       * Extra function to filter when only mysqli_real_escape_string is needed
  104.       * @access public
  105.       * @param mixed $data
  106.       * @return mixed $data
  107.       */
  108.      public function escape( $data )
  109.      {
  110.          if( !is_array( $data ) )
  111.          {
  112.              $data = $this->link->real_escape_string( $data );
  113.          }
  114.          else
  115.          {
  116.              //Self call function to sanitize array data
  117.              $data = array_map( array( $this, 'escape' ), $data );
  118.          }
  119.          return $data;
  120.      }
  121.    
  122.    
  123.     /**
  124.      * Normalize sanitized data for display (reverse $database->filter cleaning)
  125.      *
  126.      * Example usage:
  127.      * echo $database->clean( $data_from_database );
  128.      *
  129.      * @access public
  130.      * @param string $data
  131.      * @return string $data
  132.      */
  133.      public function clean( $data )
  134.      {
  135.          $data = stripslashes( $data );
  136.          $data = html_entity_decode( $data, ENT_QUOTES, 'UTF-8' );
  137.          $data = nl2br( $data );
  138.          $data = urldecode( $data );
  139.          return $data;
  140.      }
  141.    
  142.    
  143.     /**
  144.      * Determine if common non-encapsulated fields are being used
  145.      *
  146.      * Example usage:
  147.      * if( $database->db_common( $query ) )
  148.      * {
  149.      *      //Do something
  150.      * }
  151.      * Used by function exists
  152.      *
  153.      * @access public
  154.      * @param string
  155.      * @param array
  156.      * @return bool
  157.      *
  158.      */
  159.     public function db_common( $value = '' )
  160.     {
  161.         if( is_array( $value ) )
  162.         {
  163.             foreach( $value as $v )
  164.             {
  165.                 if( preg_match( '/AES_DECRYPT/i', $v ) || preg_match( '/AES_ENCRYPT/i', $v ) || preg_match( '/now()/i', $v ) )
  166.                 {
  167.                     return true;
  168.                 }
  169.                 else
  170.                 {
  171.                     return false;
  172.                 }
  173.             }
  174.         }
  175.         else
  176.         {
  177.             if( preg_match( '/AES_DECRYPT/i', $value ) || preg_match( '/AES_ENCRYPT/i', $value ) || preg_match( '/now()/i', $value ) )
  178.             {
  179.                 return true;
  180.             }
  181.         }
  182.     }
  183.    
  184.    
  185.     /**
  186.      * Perform queries
  187.      * All following functions run through this function
  188.      *
  189.      * @access public
  190.      * @param string
  191.      * @return string
  192.      * @return array
  193.      * @return bool
  194.      *
  195.      */
  196.     public function query( $query )
  197.     {
  198.         $full_query = $this->link->query( $query );
  199.         if( $this->link->error )
  200.         {
  201.             $this->log_db_errors( $this->link->error, $query );
  202.             return false;
  203.         }
  204.         else
  205.         {
  206.             return true;
  207.         }
  208.     }
  209.    
  210.    
  211.     /**
  212.      * Determine if database table exists
  213.      * Example usage:
  214.      * if( !$database->table_exists( 'checkingfortable' ) )
  215.      * {
  216.      *      //Install your table or throw error
  217.      * }
  218.      *
  219.      * @access public
  220.      * @param string
  221.      * @return bool
  222.      *
  223.      */
  224.      public function table_exists( $name )
  225.      {
  226.          self::$counter++;
  227.          $check = $this->link->query( "SELECT 1 FROM $name" );
  228.          if($check !== false)
  229.          {
  230.              if( $check->num_rows > 0 )
  231.              {
  232.                  return true;
  233.              }
  234.              else
  235.              {
  236.                  return false;
  237.              }
  238.          }
  239.          else
  240.          {
  241.              return false;
  242.          }
  243.      }
  244.    
  245.    
  246.     /**
  247.      * Count number of rows found matching a specific query
  248.      *
  249.      * Example usage:
  250.      * $rows = $database->num_rows( "SELECT id FROM users WHERE user_id = 44" );
  251.      *
  252.      * @access public
  253.      * @param string
  254.      * @return int
  255.      *
  256.      */
  257.     public function num_rows( $query )
  258.     {
  259.         self::$counter++;
  260.         $num_rows = $this->link->query( $query );
  261.         if( $this->link->error )
  262.         {
  263.             $this->log_db_errors( $this->link->error, $query );
  264.             return $this->link->error;
  265.         }
  266.         else
  267.         {
  268.             return $num_rows->num_rows;
  269.         }
  270.     }
  271.    
  272.    
  273.     /**
  274.      * Run check to see if value exists, returns true or false
  275.      *
  276.      * Example Usage:
  277.      * $check_user = array(
  278.      *    'user_email' => 'someuser@gmail.com',
  279.      *    'user_id' => 48
  280.      * );
  281.      * $exists = $database->exists( 'your_table', 'user_id', $check_user );
  282.      *
  283.      * @access public
  284.      * @param string database table name
  285.      * @param string field to check (i.e. 'user_id' or COUNT(user_id))
  286.      * @param array column name => column value to match
  287.      * @return bool
  288.      *
  289.      */
  290.     public function exists( $table = '', $check_val = '', $params = array() )
  291.     {
  292.         self::$counter++;
  293.         if( empty($table) || empty($check_val) || empty($params) )
  294.         {
  295.             return false;
  296.         }
  297.         $check = array();
  298.         foreach( $params as $field => $value )
  299.         {
  300.             if( !empty( $field ) && !empty( $value ) )
  301.             {
  302.                 //Check for frequently used mysql commands and prevent encapsulation of them
  303.                 if( $this->db_common( $value ) )
  304.                 {
  305.                     $check[] = "$field = $value";  
  306.                 }
  307.                 else
  308.                 {
  309.                     $check[] = "$field = '$value'";  
  310.                 }
  311.             }
  312.  
  313.         }
  314.         $check = implode(' AND ', $check);
  315.  
  316.         $rs_check = "SELECT $check_val FROM ".$table." WHERE $check";
  317.         $number = $this->num_rows( $rs_check );
  318.         if( $number === 0 )
  319.         {
  320.             return false;
  321.         }
  322.         else
  323.         {
  324.             return true;
  325.         }
  326.     }
  327.    
  328.    
  329.     /**
  330.      * Return specific row based on db query
  331.      *
  332.      * Example usage:
  333.      * list( $name, $email ) = $database->get_row( "SELECT name, email FROM users WHERE user_id = 44" );
  334.      *
  335.      * @access public
  336.      * @param string
  337.      * @param bool $object (true returns results as objects)
  338.      * @return array
  339.      *
  340.      */
  341.     public function get_row( $query, $object = false )
  342.     {
  343.         self::$counter++;
  344.         $row = $this->link->query( $query );
  345.         if( $this->link->error )
  346.         {
  347.             $this->log_db_errors( $this->link->error, $query );
  348.             return false;
  349.         }
  350.         else
  351.         {
  352.             $r = ( !$object ) ? $row->fetch_row() : $row->fetch_object();
  353.             return $r;  
  354.         }
  355.     }
  356.    
  357.    
  358.     /**
  359.      * Perform query to retrieve array of associated results
  360.      *
  361.      * Example usage:
  362.      * $users = $database->get_results( "SELECT name, email FROM users ORDER BY name ASC" );
  363.      * foreach( $users as $user )
  364.      * {
  365.      *      echo $user['name'] . ': '. $user['email'] .'<br />';
  366.      * }
  367.      *
  368.      * @access public
  369.      * @param string
  370.      * @param bool $object (true returns object)
  371.      * @return array
  372.      *
  373.      */
  374.     public function get_results( $query, $object = false )
  375.     {
  376.         self::$counter++;
  377.         //Overwrite the $row var to null
  378.         $row = null;
  379.        
  380.         $results = $this->link->query( $query );
  381.         if( $this->link->error )
  382.         {
  383.             $this->log_db_errors( $this->link->error, $query );
  384.             return false;
  385.         }
  386.         else
  387.         {
  388.             $row = array();
  389.             while( $r = ( !$object ) ? $results->fetch_assoc() : $results->fetch_object() )
  390.             {
  391.                 $row[] = $r;
  392.             }
  393.             return $row;  
  394.         }
  395.     }
  396.    
  397.    
  398.     /**
  399.      * Insert data into database table
  400.      *
  401.      * Example usage:
  402.      * $user_data = array(
  403.      *      'name' => 'Bennett',
  404.      *      'email' => 'email@address.com',
  405.      *      'active' => 1
  406.      * );
  407.      * $database->insert( 'users_table', $user_data );
  408.      *
  409.      * @access public
  410.      * @param string table name
  411.      * @param array table column => column value
  412.      * @return bool
  413.      *
  414.      */
  415.     public function insert( $table, $variables = array() )
  416.     {
  417.         self::$counter++;
  418.         //Make sure the array isn't empty
  419.         if( empty( $variables ) )
  420.         {
  421.             return false;
  422.         }
  423.        
  424.         $sql = "INSERT INTO ". $table;
  425.         $fields = array();
  426.         $values = array();
  427.         foreach( $variables as $field => $value )
  428.         {
  429.             $fields[] = $field;
  430.             $values[] = "'".$value."'";
  431.         }
  432.         $fields = ' (' . implode(', ', $fields) . ')';
  433.         $values = '('. implode(', ', $values) .')';
  434.        
  435.         $sql .= $fields .' VALUES '. $values;
  436.  
  437.         $query = $this->link->query( $sql );
  438.        
  439.         if( $this->link->error )
  440.         {
  441.             //return false;
  442.             $this->log_db_errors( $this->link->error, $sql );
  443.             return false;
  444.         }
  445.         else
  446.         {
  447.             return true;
  448.         }
  449.     }
  450.    
  451.    
  452.     /**
  453.     * Insert data KNOWN TO BE SECURE into database table
  454.     * Ensure that this function is only used with safe data
  455.     * No class-side sanitizing is performed on values found to contain common sql commands
  456.     * As dictated by the db_common function
  457.     * All fields are assumed to be properly encapsulated before initiating this function
  458.     *
  459.     * @access public
  460.     * @param string table name
  461.     * @param array table column => column value
  462.     * @return bool
  463.     */
  464.     public function insert_safe( $table, $variables = array() )
  465.     {
  466.         self::$counter++;
  467.         //Make sure the array isn't empty
  468.         if( empty( $variables ) )
  469.         {
  470.             return false;
  471.         }
  472.        
  473.         $sql = "INSERT INTO ". $table;
  474.         $fields = array();
  475.         $values = array();
  476.         foreach( $variables as $field => $value )
  477.         {
  478.             $fields[] = $this->filter( $field );
  479.             //Check for frequently used mysql commands and prevent encapsulation of them
  480.             $values[] = $value;
  481.         }
  482.         $fields = ' (' . implode(', ', $fields) . ')';
  483.         $values = '('. implode(', ', $values) .')';
  484.        
  485.         $sql .= $fields .' VALUES '. $values;
  486.         $query = $this->link->query( $sql );
  487.        
  488.         if( $this->link->error )
  489.         {
  490.             $this->log_db_errors( $this->link->error, $sql );
  491.             return false;
  492.         }
  493.         else
  494.         {
  495.             return true;
  496.         }
  497.     }
  498.    
  499.    
  500.     /**
  501.      * Insert multiple records in a single query into a database table
  502.      *
  503.      * Example usage:
  504.      * $fields = array(
  505.      *      'name',
  506.      *      'email',
  507.      *      'active'
  508.      *  );
  509.      *  $records = array(
  510.      *     array(
  511.      *          'Bennett', 'bennett@email.com', 1
  512.      *      ),
  513.      *      array(
  514.      *          'Lori', 'lori@email.com', 0
  515.      *      ),
  516.      *      array(
  517.      *          'Nick', 'nick@nick.com', 1, 'This will not be added'
  518.      *      ),
  519.      *      array(
  520.      *          'Meghan', 'meghan@email.com', 1
  521.      *      )
  522.      * );
  523.      *  $database->insert_multi( 'users_table', $fields, $records );
  524.      *
  525.      * @access public
  526.      * @param string table name
  527.      * @param array table columns
  528.      * @param nested array records
  529.      * @return bool
  530.      * @return int number of records inserted
  531.      *
  532.      */
  533.     public function insert_multi( $table, $columns = array(), $records = array() )
  534.     {
  535.         self::$counter++;
  536.         //Make sure the arrays aren't empty
  537.         if( empty( $columns ) || empty( $records ) )
  538.         {
  539.             return false;
  540.         }
  541.  
  542.         //Count the number of fields to ensure insertion statements do not exceed the same num
  543.         $number_columns = count( $columns );
  544.  
  545.         //Start a counter for the rows
  546.         $added = 0;
  547.  
  548.         //Start the query
  549.         $sql = "INSERT INTO ". $table;
  550.  
  551.         $fields = array();
  552.         //Loop through the columns for insertion preparation
  553.         foreach( $columns as $field )
  554.         {
  555.             $fields[] = '`'.$field.'`';
  556.         }
  557.         $fields = ' (' . implode(', ', $fields) . ')';
  558.  
  559.         //Loop through the records to insert
  560.         $values = array();
  561.         foreach( $records as $record )
  562.         {
  563.             //Only add a record if the values match the number of columns
  564.             if( count( $record ) == $number_columns )
  565.             {
  566.                 $values[] = '(\''. implode( '\', \'', array_values( $record ) ) .'\')';
  567.                 $added++;
  568.             }
  569.         }
  570.         $values = implode( ', ', $values );
  571.  
  572.         $sql .= $fields .' VALUES '. $values;
  573.  
  574.         $query = $this->link->query( $sql );
  575.  
  576.         if( $this->link->error )
  577.         {
  578.             $this->log_db_errors( $this->link->error, $sql );
  579.             return false;
  580.         }
  581.         else
  582.         {
  583.             return $added;
  584.         }
  585.     }
  586.    
  587.    
  588.     /**
  589.      * Update data in database table
  590.      *
  591.      * Example usage:
  592.      * $update = array( 'name' => 'Not bennett', 'email' => 'someotheremail@email.com' );
  593.      * $update_where = array( 'user_id' => 44, 'name' => 'Bennett' );
  594.      * $database->update( 'users_table', $update, $update_where, 1 );
  595.      *
  596.      * @access public
  597.      * @param string table name
  598.      * @param array values to update table column => column value
  599.      * @param array where parameters table column => column value
  600.      * @param int limit
  601.      * @return bool
  602.      *
  603.      */
  604.     public function update( $table, $variables = array(), $where = array(), $limit = '' )
  605.     {
  606.         self::$counter++;
  607.         //Make sure the required data is passed before continuing
  608.         //This does not include the $where variable as (though infrequently)
  609.         //queries are designated to update entire tables
  610.         if( empty( $variables ) )
  611.         {
  612.             return false;
  613.         }
  614.         $sql = "UPDATE ". $table ." SET ";
  615.         foreach( $variables as $field => $value )
  616.         {
  617.            
  618.             $updates[] = "`$field` = '$value'";
  619.         }
  620.         $sql .= implode(', ', $updates);
  621.        
  622.         //Add the $where clauses as needed
  623.         if( !empty( $where ) )
  624.         {
  625.             foreach( $where as $field => $value )
  626.             {
  627.                 $value = $value;
  628.  
  629.                 $clause[] = "$field = '$value'";
  630.             }
  631.             $sql .= ' WHERE '. implode(' AND ', $clause);  
  632.         }
  633.        
  634.         if( !empty( $limit ) )
  635.         {
  636.             $sql .= ' LIMIT '. $limit;
  637.         }
  638.  
  639.         $query = $this->link->query( $sql );
  640.  
  641.         if( $this->link->error )
  642.         {
  643.             $this->log_db_errors( $this->link->error, $sql );
  644.             return false;
  645.         }
  646.         else
  647.         {
  648.             return true;
  649.         }
  650.     }
  651.    
  652.    
  653.     /**
  654.      * Delete data from table
  655.      *
  656.      * Example usage:
  657.      * $where = array( 'user_id' => 44, 'email' => 'someotheremail@email.com' );
  658.      * $database->delete( 'users_table', $where, 1 );
  659.      *
  660.      * @access public
  661.      * @param string table name
  662.      * @param array where parameters table column => column value
  663.      * @param int max number of rows to remove.
  664.      * @return bool
  665.      *
  666.      */
  667.     public function delete( $table, $where = array(), $limit = '' )
  668.     {
  669.         self::$counter++;
  670.         //Delete clauses require a where param, otherwise use "truncate"
  671.         if( empty( $where ) )
  672.         {
  673.             return false;
  674.         }
  675.        
  676.         $sql = "DELETE FROM ". $table;
  677.         foreach( $where as $field => $value )
  678.         {
  679.             $value = $value;
  680.             $clause[] = "$field = '$value'";
  681.         }
  682.         $sql .= " WHERE ". implode(' AND ', $clause);
  683.        
  684.         if( !empty( $limit ) )
  685.         {
  686.             $sql .= " LIMIT ". $limit;
  687.         }
  688.            
  689.         $query = $this->link->query( $sql );
  690.  
  691.         if( $this->link->error )
  692.         {
  693.             //return false; //
  694.             $this->log_db_errors( $this->link->error, $sql );
  695.             return false;
  696.         }
  697.         else
  698.         {
  699.             return true;
  700.         }
  701.     }
  702.    
  703.    
  704.     /**
  705.      * Get last auto-incrementing ID associated with an insertion
  706.      *
  707.      * Example usage:
  708.      * $database->insert( 'users_table', $user );
  709.      * $last = $database->lastid();
  710.      *
  711.      * @access public
  712.      * @param none
  713.      * @return int
  714.      *
  715.      */
  716.     public function lastid()
  717.     {
  718.         self::$counter++;
  719.         return $this->link->insert_id;
  720.     }
  721.    
  722.    
  723.     /**
  724.      * Return the number of rows affected by a given query
  725.      *
  726.      * Example usage:
  727.      * $database->insert( 'users_table', $user );
  728.      * $database->affected();
  729.      *
  730.      * @access public
  731.      * @param none
  732.      * @return int
  733.      */
  734.     public function affected()
  735.     {
  736.         return $this->link->affected_rows;
  737.     }
  738.    
  739.    
  740.     /**
  741.      * Get number of fields
  742.      *
  743.      * Example usage:
  744.      * echo $database->num_fields( "SELECT * FROM users_table" );
  745.      *
  746.      * @access public
  747.      * @param query
  748.      * @return int
  749.      */
  750.     public function num_fields( $query )
  751.     {
  752.         self::$counter++;
  753.         $query = $this->link->query( $query );
  754.         $fields = $query->field_count;
  755.         return $fields;
  756.     }
  757.    
  758.    
  759.     /**
  760.      * Get field names associated with a table
  761.      *
  762.      * Example usage:
  763.      * $fields = $database->list_fields( "SELECT * FROM users_table" );
  764.      * echo '<pre>';
  765.      * print_r( $fields );
  766.      * echo '</pre>';
  767.      *
  768.      * @access public
  769.      * @param query
  770.      * @return array
  771.      */
  772.     public function list_fields( $query )
  773.     {
  774.         self::$counter++;
  775.         $query = $this->link->query( $query );
  776.         $listed_fields = $query->fetch_fields();
  777.         return $listed_fields;
  778.     }
  779.    
  780.    
  781.     /**
  782.      * Truncate entire tables
  783.      *
  784.      * Example usage:
  785.      * $remove_tables = array( 'users_table', 'user_data' );
  786.      * echo $database->truncate( $remove_tables );
  787.      *
  788.      * @access public
  789.      * @param array database table names
  790.      * @return int number of tables truncated
  791.      *
  792.      */
  793.     public function truncate( $tables = array() )
  794.     {
  795.         if( !empty( $tables ) )
  796.         {
  797.             $truncated = 0;
  798.             foreach( $tables as $table )
  799.             {
  800.                 $truncate = "TRUNCATE TABLE `".trim($table)."`";
  801.                 $this->link->query( $truncate );
  802.                 if( !$this->link->error )
  803.                 {
  804.                     $truncated++;
  805.                     self::$counter++;
  806.                 }
  807.             }
  808.             return $truncated;
  809.         }
  810.     }
  811.    
  812.    
  813.     /**
  814.      * Output results of queries
  815.      *
  816.      * @access public
  817.      * @param string variable
  818.      * @param bool echo [true,false] defaults to true
  819.      * @return string
  820.      *
  821.      */
  822.     public function display( $variable, $echo = true )
  823.     {
  824.         $out = '';
  825.         if( !is_array( $variable ) )
  826.         {
  827.             $out .= $variable;
  828.         }
  829.         else
  830.         {
  831.             $out .= '<pre>';
  832.             $out .= print_r( $variable, TRUE );
  833.             $out .= '</pre>';
  834.         }
  835.         if( $echo === true )
  836.         {
  837.             echo $out;
  838.         }
  839.         else
  840.         {
  841.             return $out;
  842.         }
  843.     }
  844.    
  845.    
  846.     /**
  847.      * Output the total number of queries
  848.      * Generally designed to be used at the bottom of a page after
  849.      * scripts have been run and initialized as needed
  850.      *
  851.      * Example usage:
  852.      * echo 'There were '. $database->total_queries() . ' performed';
  853.      *
  854.      * @access public
  855.      * @param none
  856.      * @return int
  857.      */
  858.     public function total_queries()
  859.     {
  860.         return self::$counter;
  861.     }
  862.    
  863.    
  864.     /**
  865.      * Singleton function
  866.      *
  867.      * Example usage:
  868.      * $database = DB::getInstance();
  869.      *
  870.      * @access private
  871.      * @return self
  872.      */
  873.     static function getInstance()
  874.     {
  875.         if( self::$inst == null )
  876.         {
  877.             self::$inst = new DB();
  878.         }
  879.         return self::$inst;
  880.     }
  881.    
  882.    
  883.     /**
  884.      * Disconnect from db server
  885.      * Called automatically from __destruct function
  886.      */
  887.     public function disconnect()
  888.     {
  889.         $this->link->close();
  890.     }
  891.  
  892. } //end class DB
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement