Advertisement
Guest User

Untitled

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