Re: Better DB Class MySQL

From: Date: Sun, 10 Feb 2008 15:31:43 +0000
Subject: Re: Better DB Class MySQL
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-269034@lists.php.net to get a copy of this message
Larry Garfield schreef:
http://www.php.net/pdo All the cool kids are doing it.
not true - some of them use firebird ;-)
On Saturday 09 February 2008, nihilism machine wrote:
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(); } } ?>


« previous php.general (#269034) next »