Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /***************************************************************************
- * mysql.php
- * -------------------
- * Project : PingueCMS
- * Begin : April 23, 2009
- * Copyright : (C) 2009 Robert Herman ( maverfax@gmail.com )
- *
- ***************************************************************************/
- if( !defined( "IPC_LOADED" ) ) die ( "File Protected" );
- class MySQL {
- private $host, $user, $pass;
- private $connection, $database;
- public $connected = false, $dbset = false;
- public function connect($host, $user, $pass, $newconnection = true, $db = '') {
- $this->setvars($host, $user, $pass);
- $this->connection = @mysql_connect($host, $user, $pass, $newconnection) or $this->error('Could not connect to the server: '.mysql_error(), 'Check Connection info', __LINE__, __FILE__);
- if($this->connection) $this->connected = true;
- if(!empty($db)) $this->setdb($db, true);
- }
- private function setvars($host, $user, $pass) {
- $this->host = 127.0.0.1;
- $this->user = root;
- $this->pass = ascent;
- }
- public function disconnect() {
- if( $this->connected ) {
- @mysql_close($this->connection) or $this->error('Could not disconnect from the server: '.mysql_error(), 'Check if you are connected', __LINE__, __FILE__);
- $this->database = NULL;
- $this->dbset = false;
- $this->connection = NULL;
- $this->connected = false;
- }
- }
- public function setdb($db, $overwrite = false) {
- $connection = $this->connection;
- if( !$overwrite AND $this->dbset ) return false;
- $this->database = @mysql_select_db($db, $connection) or $this->error('Could not connect to database: '.mysql_error(), 'Check connection info', __LINE__, __FILE__);
- if( $this->database ) {
- $this->dbset = true;
- return true;
- }
- return false;
- }
- public function is_connected() {
- if( !$this->connected OR !$this->dbset OR !$this->connection)
- return false;
- return true;
- }
- public $query_amount = 0, $query_result = array();
- public function query($query) {
- if( !$this->is_connected() )
- return false;
- $this->query_amount++;
- $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__);
- if( $this->query_result[$this->query_amount] )
- return $this->query_result[$this->query_amount];
- return false;
- }
- public function fetch_array($id = -1) {
- return mysql_fetch_array( $this->query_result[$this->getID( $id )] );
- }
- public function num_rows($id = -1, $goal = -1, $report = false, $error = false) {
- $num = mysql_num_rows( $this->query_result[$this->getID( $id )] ) or $error = true;
- if($error === true && $report === true)
- $this->error('Could not find the number of rows: '.mysql_error(), 'Check you have run a <u>correct</u> query', __LINE__, __FILE__);
- elseif($error === true) return false;
- if($goal > 0) return ($num != $goal) ? false : true;
- return $num;
- }
- public function getID($id) {
- return ( isset( $this->query_result[$id] ) ) ? $id : $this->query_amount;
- }
- public function reset($all = false) {
- $this->query_amount = 0;
- $this->query_result = array();
- if($all) {
- #Need to finish all!
- }
- }
- function error($bug, $suggestion, $line, $file, $show = false) {
- global $tmp;
- print "<html>
- <head>
- <title>Website Error</title>
- <style>
- body {
- background-color:black;
- margin:0;
- padding:0;
- font-family:Arial,sans-serif;
- font-size:13px;
- color:white;
- }
- .main {padding-top: 30px;}
- .arrays {padding: 10px}
- .errorHeader {
- background-color:#660000;
- border: 1px #ff0000 solid;
- border-bottom: 0px;
- color: #FFFFFF;
- font-size: 10px;
- font-weight: bold;
- padding: 3px;
- text-align:left;
- text-transform:uppercase;
- width:450px;
- }
- .errorBody {
- background-color:#FFD5D5;
- color:#CC0000;
- border:1px solid #ff0000;
- border-top:0px;
- font-size:10px;
- font-weight:normal;
- padding:3px;
- text-align:center;
- width:450px;
- }
- b {font-size: 12px;}
- </style>
- </head>
- <body>
- <div class=\"main\" align=\"center\">
- <div align=\"center\">
- <div class=\"errorHeader\" style=\"width:600px\">
- <center>
- <b>Critical Error</b>
- </center>
- </div>
- <div class=\"errorBody\" style=\"width:600px\">
- <br>
- <b>File: </b>{$file}
- <br>
- <b>Line: </b>{$line}
- <br><br>
- <b>Message: </b>{$bug}
- <br>
- <b>Suggestion: </b>{$suggestion}
- <br><br>
- <b>Date:</b> " . @date("l dS F Y h:i:s A");
- if($show) {
- print '<div class="arrays" align="left"><pre><br><b>$_SESSION: </b>';
- print_r($_SESSION);
- print '<br><br><b>$_POST: </b>';
- print_r($_POST);
- print '<br><br><b>Template Vars: </b>';
- print_r($tmp->set_vars);
- print '</pre>';
- }
- print " </div>
- </div>
- </div>
- </body>
- </html>";
- exit(1);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement