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
https://forums.phpfreaks.com/topic/135981-php-5-class/
Share on other sites

You know using @ to suppress errors isn't very good coding practice, you should fix any errors or alerts etc.. there might be.

 

Or on live sites i use customer errors and error_reporting(0); to turn errors off, but i still try and fix any other errors there might be.

Link to comment
https://forums.phpfreaks.com/topic/135981-php-5-class/#findComment-708848
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.