Jump to content

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

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.