Jump to content

database class


xtremey_ytinasni

Recommended Posts

Would this be a decent class to use, or is there anything I should add,edit, or remove?

 

<?php
/**
* MySQL Database Class
*
* @author: Dillion DeWitt
* @copyright: Dillion DeWitt (c), 2012.
*/

class DB {

	var $link;
	var $host;
	var $user;
	var $password;
	var $database;
	var $query;
	var $result;
	var $debug=false;

		function connect($host,$user,$pass,$database=false,$persistent=false){
		    //Assign values to class variables.
			$this->host = $host;
			$this->user = $user;
			$this->password = $pass;

			if( $persistent ){
				$this->link = mysql_pconnect($host,$user,$pass); 
			} else {
				$this->link = mysql_connect($host,$user,$pass);
			}

			if( $database ){
				$this->database = $database;
				mysql_select_db($database,$this->link);
			}

		}

		function isConnected(){

			if(mysql_ping($this-link) === true){
				$msg = 'Connected.';
			} else {
				$msg = 'Disconnected.';
			}

			return $msg;

		}

		function query($sql){

			$this->query = $sql;
			$this->result = mysql_query($sql, $this->link) or $this->Error();

		}

		function num_rows($result){
			$result = $this->result;
				return mysql_num_rows($result);
		}

		function get_single($result){
			$result = $this->result;
				return mysql_fetch_row($result);
		}

		function get_rows($result){
			$result = $this->result;
				return mysql_fetch_assoc($result);
		}

		function Error(){

			if($this->debug){
				echo mysql_errno().': '.mysql_error();
				exit;
			} else {
				echo 'An error has occured.';
				exit;
			}

		}

}

?>

Link to comment
https://forums.phpfreaks.com/topic/254924-database-class/
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.