Advertisement
Guest User

Untitled

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