Advertisement
Guest User

Untitled

a guest
May 26th, 2017
496
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.16 KB | None | 0 0
  1. <?php
  2. /***************************************************************************
  3.  *                                mysql.php
  4.  *                            -------------------
  5.  *   Project              : PingueCMS
  6.  *   Begin                : April 23, 2009
  7.  *   Copyright            : (C) 2009 Robert Herman ( maverfax@gmail.com )
  8.  *
  9.  ***************************************************************************/
  10.  
  11. if( !defined( "IPC_LOADED" ) ) die ( "File Protected" );
  12.  
  13. class MySQL {
  14.     private $host, $user, $pass;
  15.     private $connection, $database;
  16.     public $connected = false, $dbset = false;
  17.    
  18.     public function connect($host, $user, $pass, $newconnection = true, $db = '') {
  19.         $this->setvars($host, $user, $pass);
  20.         $this->connection = @mysql_connect($host, $user, $pass, $newconnection) or $this->error('Could not connect to the server: '.mysql_error(), 'Check Connection info', __LINE__, __FILE__);
  21.            
  22.         if($this->connection) $this->connected = true;
  23.        
  24.         if(!empty($db)) $this->setdb($db, true);
  25.     }
  26.  
  27.     private function setvars($host, $user, $pass) {
  28.         $this->host = $host;
  29.         $this->user = $user;
  30.         $this->pass = $pass;
  31.     }
  32.    
  33.     public function disconnect() {
  34.         if( $this->connected ) {
  35.             @mysql_close($this->connection) or $this->error('Could not disconnect from the server: '.mysql_error(), 'Check if you are connected', __LINE__, __FILE__);
  36.            
  37.             $this->database = NULL;
  38.             $this->dbset = false;
  39.            
  40.             $this->connection = NULL;
  41.             $this->connected = false;
  42.         }
  43.     }
  44.    
  45.     public function setdb($db, $overwrite = false) {
  46.         $connection = $this->connection;   
  47.            
  48.         if( !$overwrite AND $this->dbset ) return false;
  49.    
  50.         $this->database = @mysql_select_db($db, $connection) or $this->error('Could not connect to database: '.mysql_error(), 'Check connection info', __LINE__, __FILE__);
  51.        
  52.         if( $this->database ) {
  53.             $this->dbset = true;
  54.             return true;
  55.         }
  56.         return false;
  57.     }
  58.    
  59.     public function is_connected() {
  60.         if( !$this->connected OR !$this->dbset OR !$this->connection)
  61.             return false;
  62.             return true;
  63.     }
  64.    
  65.     public $query_amount = 0, $query_result = array();
  66.     public function query($query) {
  67.         if( !$this->is_connected() )
  68.           return false;
  69.        
  70.         $this->query_amount++;
  71.         $this->query_result[$this->query_amount] = mysql_query($query, $this->connection) or $this->error('Error in query with '.$this->connection.': '.mysql_error(), 'Check the query', __LINE__, __FILE__);
  72.        
  73.         if( $this->query_result[$this->query_amount] )
  74.             return $this->query_result[$this->query_amount];
  75.             return false;
  76.     }
  77.        
  78.     public function fetch_array($id = -1) {
  79.         return mysql_fetch_array( $this->query_result[$this->getID( $id )] );
  80.     }
  81.    
  82.     public function num_rows($id = -1, $goal = -1, $report = false, $error = false) {
  83.         $num = mysql_num_rows( $this->query_result[$this->getID( $id )] ) or $error = true;
  84.         if($error === true && $report === true)
  85.           $this->error('Could not find the number of rows: '.mysql_error(), 'Check you have run a <u>correct</u> query', __LINE__, __FILE__);
  86.         elseif($error === true) return false;
  87.         if($goal > 0) return ($num != $goal) ? false : true;
  88.         return $num;
  89.     }
  90.    
  91.     public function getID($id) {       
  92.         return ( isset( $this->query_result[$id] ) ) ? $id : $this->query_amount;
  93.     }
  94.    
  95.     public function reset($all = false) {
  96.         $this->query_amount = 0;
  97.         $this->query_result = array();
  98.         if($all) {
  99.           #Need to finish all! 
  100.         }
  101.     }
  102.    
  103.     function error($bug, $suggestion, $line, $file, $show = false) {
  104.     global $tmp;
  105.     print "<html>
  106.       <head>
  107.         <title>Website Error</title>
  108.         <style>
  109.             body {
  110.                 background-color:black;
  111.                 margin:0;
  112.                 padding:0;
  113.                 font-family:Arial,sans-serif;
  114.                 font-size:13px;
  115.                 color:white;
  116.             }
  117.             .main {padding-top: 30px;}
  118.             .arrays {padding: 10px}
  119.             .errorHeader {
  120.                 background-color:#660000;
  121.                 border: 1px #ff0000 solid;
  122.                 border-bottom: 0px;
  123.                 color: #FFFFFF;
  124.                 font-size: 10px;
  125.                 font-weight: bold;
  126.                 padding: 3px;
  127.                 text-align:left;
  128.                 text-transform:uppercase;
  129.                 width:450px;
  130.             }
  131.             .errorBody {
  132.                 background-color:#FFD5D5;
  133.                 color:#CC0000;
  134.                 border:1px solid #ff0000;
  135.                 border-top:0px;
  136.                 font-size:10px;
  137.                 font-weight:normal;
  138.                 padding:3px;
  139.                 text-align:center;
  140.                 width:450px;
  141.             }
  142.             b {font-size: 12px;}
  143.         </style>
  144.       </head>
  145.       <body>
  146.       <div class=\"main\" align=\"center\">
  147.         <div align=\"center\">
  148.           <div class=\"errorHeader\" style=\"width:600px\">
  149.             <center>
  150.               <b>Critical Error</b>
  151.             </center>
  152.           </div>
  153.           <div class=\"errorBody\" style=\"width:600px\">
  154.             <br>
  155.             <b>File: </b>{$file}
  156.             <br>
  157.             <b>Line: </b>{$line}
  158.             <br><br>
  159.             <b>Message: </b>{$bug}
  160.             <br>
  161.             <b>Suggestion: </b>{$suggestion}
  162.             <br><br>
  163.             <b>Date:</b> " . @date("l dS F Y h:i:s A");
  164.  
  165.     if($show) {
  166.         print '<div class="arrays" align="left"><pre><br><b>$_SESSION: </b>';
  167.         print_r($_SESSION);
  168.         print '<br><br><b>$_POST: </b>';
  169.         print_r($_POST);
  170.         print '<br><br><b>Template Vars: </b>';
  171.         print_r($tmp->set_vars);
  172.         print '</pre>';
  173.     }
  174. print "     </div>
  175.    </div>
  176.       </div>
  177.       </body>
  178.     </html>";
  179.     exit(1);
  180.     }
  181. }
  182. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement