Better DB Class MySQL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Looking to really beef up my DB class, any suggestions for functions to add that will be more time saving for a web 2.0 app, or ways to improve existing methods? thank you everyone in advance.

<?php

class db {

	//	Members
	public $db_user = "";
	public $db_pass = "";
	public $db_name = "";
	public $db_server = "";
	public $link;
	public $result_id;

	//	Methods
	public function __construct() {
		$this->connect();
	}

	// Connect to MySQL Server
	public function connect() {
$this->link = mysql_connect($this->db_server,$this->db_user,$this- >db_pass) or die("Error: Cannot Connect to DataBase"); mysql_select_db($this->db_name,$this->link) or die("Error: Cannot Select Database (" . $this->db_name . ")");
	}

	// MySQL Query
	public function query($sql) {
		$this->result_id = mysql_query($sql);
		return $this->fetch_rows();
	}	

	// MySQL Query
	public function insert($sql) {
		$this->result_id = mysql_query($sql);
		return $this->select_id;
	}
		
	// MySQL Fetch Rows
	public function fetch_rows() {
		$rows = array();
		if($this->result_id){
			while($row = mysql_fetch_object($this->result_id)) {
				$rows[] = $row;
			}		
		}
		return $rows;	
	}

	// MySQL Affected Rows
	public function num_rows() {
		return mysql_num_rows($this->link);
	}
	
	// MySQL Affected Rows
	public function select_id() {
		return mysql_insert_id($this->link);
	}

	// Disconnect from MySQL Server
	public function disconnect() {
		mysql_close($this->link);
	}

	// Terminator Style Function simply in coolness
	public function Terminator($tbl) {
	}
	
	// Destruct!
	public function __destruct() {
		$this->disconnect();
	}
}

?>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux