Jump to content

php 5 class


gevans

Recommended Posts

Hey, can anyone take a look at this and let me know what they think.

 

It works perfectly, just want to ensure that it's taking advantage of all php5 has to offer!

 

<?php

/*################################
*Connect and work with database
*Class set as variable: $DB
*Created: 14 August 2008
*Updated: 07 December 2008
*Copyright Purple Coffee Interactive
*Written by Gareth Evans
*/################################

class mysql{
    private $mysql, $database, $result, $url, $email;
    
    public function __construct($host,$user,$pass,$table,$url,$email){
        $this->url = $url;
        if(!$this->mysql = @mysql_connect($host,$user,$pass)) return self::error('There was a problem connecting to the database.', mysql_errno().': '.mysql_error());
        if(!$this->database = @mysql_select_db($table, $this->mysql))return self::error('There was a problem connecting to the database.', mysql_errno().': '.mysql_error());
        return true;
    }
    
    public function query($text,$r = 0){
        if(!$this->result = @mysql_query($text)){
            if($r) return self::error('There was an error while trying to complete your task.', mysql_errno().': '.mysql_error().'.\nQuery: "'.$text.'"');
            else return self::errmail(mysql_errno().': '.mysql_error().'<br />"'.$text.'"');
        } else return $this->result;
    }

    public function num_rows($text){
        if($this->result = @mysql_num_rows($text)) return $this->result;
        else return false;
    }

    public function fetch_array($text){
        if($this->result = @mysql_fetch_array($text)) return $this->result;
        else return false;
    }

    private function error($text, $err){
        echo $text.'<br />';
        self::errmail($err);
        return false;
    }

    private function errmail($err){
        @mail($this->email, 'MySQL: error', $this->url."\n\n".$err, 'From: mysql.php');
        return false;
    }

    public function __destruct(){
        @mysql_close($this->mysql);
    }
}
?>

 

Cheers guys  :)

Link to comment
Share on other sites

Ok, cheers for that. As far as I'm aware it is set to error_reporting(0) on my servers, will be double checking that.

 

Have everything without @ when local.

 

Apart from that does everything look ok (as far as working to a decent standard)?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.