gevans Posted December 7, 2008 Share Posted December 7, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/135981-php-5-class/ Share on other sites More sharing options...
DeanWhitehouse Posted December 7, 2008 Share Posted December 7, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/135981-php-5-class/#findComment-708848 Share on other sites More sharing options...
gevans Posted December 7, 2008 Author Share Posted December 7, 2008 It's been fully tested without @, I added that as I've added my own error reporting that will be emailed to me rather than showing up to anyone in a browser. Quote Link to comment https://forums.phpfreaks.com/topic/135981-php-5-class/#findComment-708850 Share on other sites More sharing options...
DeanWhitehouse Posted December 7, 2008 Share Posted December 7, 2008 Ok, then to save work i would add error_reporting(0); instead of suppressing each one on its own. Quote Link to comment https://forums.phpfreaks.com/topic/135981-php-5-class/#findComment-708853 Share on other sites More sharing options...
gevans Posted December 7, 2008 Author Share Posted December 7, 2008 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)? Quote Link to comment https://forums.phpfreaks.com/topic/135981-php-5-class/#findComment-708859 Share on other sites More sharing options...
Mchl Posted December 7, 2008 Share Posted December 7, 2008 You could use exceptions to catch errors. So no, it is not using everything PHP5 can offer Quote Link to comment https://forums.phpfreaks.com/topic/135981-php-5-class/#findComment-708860 Share on other sites More sharing options...
gevans Posted December 7, 2008 Author Share Posted December 7, 2008 Haha, cheers for that!! Might just implement that later! Quote Link to comment https://forums.phpfreaks.com/topic/135981-php-5-class/#findComment-708863 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.