Return to Snippet

Revision: 14734
at August 6, 2009 21:42 by StrawMan


Updated Code
////////////////////////////////////
//Simple DB Connection class.
////////////////////////////////////
class dbconnect {
	//Variables.
	private $host;
	private $user;
	private $password;
	private $database;	
	private $lnk;
	public $result;	
		////////////////////////////		
		//Constructor.
		////////////////////////////		
		public function __construct($a, $b, $c, $d) {
			$this -> host = $a;
			$this -> user = $b;
			$this -> password = $c;
			$this -> database = $d;
		}
		////////////////////////////
		//Public class functions.
		////////////////////////////
		//Query
		public function func_query($qstring) {
			$this -> func_connect();
			mysql_query("SET NAMES 'utf8'"); 
			$this -> result = mysql_query($qstring);	
				return $this -> result;
				mysql_close($this -> lnk);
				mysql_free_result($this -> result);
		}
		////////////////////////////
		//Private class functions.
		////////////////////////////		
		//Connect.
		private function func_connect() {
			$this -> lnk = mysql_connect($this -> host, $this -> user, $this -> password, true) OR die('Could not connect to the database - Why: '.mysql_error());
			mysql_select_db($this -> database) OR die('Could not find database: '.mysql_error());	
		}		
		////////////////////////////		
		//Destructor.
		////////////////////////////
		public function __destruct() {
			unset ($this -> user, $this -> password);
		}
}
////////////////////////////////////

Revision: 14733
at August 5, 2009 20:09 by StrawMan


Updated Code
////////////////////////////////////
//Simple DB Connection class.
////////////////////////////////////
class dbconnect {
	//Variables.
	private $host;
	private $user;
	private $password;
	private $database;	
	private $lnk;
	public $result;	
		//Constructor.
		public function __construct($a, $b, $c, $d) {
			$this -> host = $a;
			$this -> user = $b;
			$this -> password = $c;
			$this -> database = $d;
		}
		//Connect.
		private function func_connect() {
			$this -> lnk = mysql_connect($this -> host, $this -> user, $this -> password, true) OR die('Could not connect to the database - Why: '.mysql_error());
			mysql_select_db($this -> database) OR die('Could not find database: '.mysql_error());	
		}
		//Query
		public function func_query($qstring) {
			$this -> func_connect();
			mysql_query("SET NAMES 'utf8'"); 
			$this -> result = mysql_query($qstring);	
				return $this -> result;
				mysql_close($this -> lnk);
                                mysql_free_result($this -> result);		
}
		//Destructor.
		public function __destruct() {
			unset ($this -> user, $this -> password);
		}
}
////////////////////////////////////

Revision: 14732
at August 3, 2009 00:39 by StrawMan


Updated Code
////////////////////////////////////
//Simple DB Connection class.
////////////////////////////////////
class dbconnect {
	//Variables.
	private $host;
	private $user;
	private $password;
	private $database;	
	private $lnk;
	public $result;	
		//Constructor.
		public function __construct($a, $b, $c, $d) {
			$this -> host = $a;
			$this -> user = $b;
			$this -> password = $c;
			$this -> database = $d;
		}
		//Connect.
		private function func_connect() {
			$this -> lnk = mysql_connect($this -> host, $this -> user, $this -> password, true) OR die('Could not connect to the database - Why: '.mysql_error());
			mysql_select_db($this -> database) OR die('Could not find database: '.mysql_error());	
		}
		//Query
		public function func_query($qstring) {
			$this -> func_connect();
			mysql_query("SET NAMES 'utf8'"); 
			$this -> result = mysql_query($qstring);	
				return $this -> result;
				mysql_close($this -> lnk);
		}
		//Destructor.
		public function __destruct() {
			unset ($this -> user, $this -> password);
			mysql_free_result($this -> result);
		}
}
////////////////////////////////////

Revision: 14731
at June 10, 2009 00:22 by StrawMan


Updated Code
////////////////////////////////////
//DB Connection class.
////////////////////////////////////
class dbconnect {
	//Variables.
	public $host;
	public $user;
	public $password;
	public $database;
	public $lnk;	
	//Constructor.
	public function __construct($a, $b, $c, $d) {
		$this -> host = $a;
		$this -> user = $b;
		$this -> password = $c;
		$this -> database = $d;
	}
	//Connect.
	public function func_connect() {
		$this -> lnk = mysql_connect($this -> host, $this -> user, $this -> password) OR die('Could not connect to the database - Why: '.mysql_error());
		mysql_select_db($this -> database) OR die('Could not find database: '.mysql_error());	
	}
	//Query
	public function func_query($qstring) {
		mysql_query("SET NAMES 'utf8'"); 
		
		$result = mysql_query($qstring);	
			return $result;
	}
	//Destructor.
	public function __destruct() {
		unset ($this -> user, $this -> password);
		mysql_close($this -> lnk);
	}
}
////////////////////////////////////

Revision: 14730
at June 10, 2009 00:20 by StrawMan


Initial Code
////////////////////////////////////
//DB Connection class.
////////////////////////////////////
class dbconnect {
	//Variables.
	public $host;
	public $user;
	public $password;
	public $database;
	public $lnk;	
		//Constructor.
		public function __construct($a, $b, $c, $d) {
			$this -> host = $a;
			$this -> user = $b;
			$this -> password = $c;
			$this -> database = $d;
		}
		//Connect.
		public function func_connect() {
			$this -> lnk = mysql_connect($this -> host, $this -> user, $this -> password) OR die('Could not connect to the database - Why: '.mysql_error());
			mysql_select_db($this -> database) OR die('Could not find database: '.mysql_error());	
		}
		//Query
		public function func_query($qstring) {
			mysql_query("SET NAMES 'utf8'"); 
			
			$result = mysql_query($qstring);	
				return $result;
		}
		//Destructor.
		public function __destruct() {
			unset ($this -> user, $this -> password);
			mysql_close($this -> lnk);
		}
}
////////////////////////////////////

Initial URL


Initial Description


Initial Title
Simple DB Connection Class

Initial Tags
database, php

Initial Language
PHP