Location: PHPKode > scripts > mydna > mydna/mydna.class.php
<?php

/**
 * 
 * Release Version : 0.1
 * Filename  : clas.db.php
 * description : 
 * mydna is a class that handle the connection and fetching the data
 * from the MySQL database
 * 
 * please refer to /doc for more information howto use this class
 * 
 * created 09/02/2004
 * Deden Fathurahman : hide@address.com
 * Ade Sugiandi : hide@address.com
 * 
 * @copyright 2005 (c) Deden & Ade
 * last modified : 29 april 2005
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 * See the GNU Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * 
 **/


class mydna{
	var $dbhost = "hostname"; 	// var hostname
	var $dbuser = "dbusername";	// var username
	var $dbpass = "dbpassword";	// var user password
	var $dbname = "db_name";	// var database name
	var $arr = array();		// declare ...
	var $Row = array();
	var $y=0;
	
	#var, var, var
	var $PERSISTENT_CONN = false;
	var $ERROR ='';
	var $CONNECT;
	
	########################################################
	# Function:    connectDB
	# Parameters:  N/A
	# description : Function for connected to the database
	######################################################
	function connectDB() {
		if ($this->PERSISTENT_CONN) {
			$conn = mysql_pconnect($this->dbhost,$this->dbuser,$this->dbpass);
		}else{
			$conn = mysql_connect($this->dbhost,$this->dbuser,$this->dbpass);
		}
		if ((!$conn) || (!mysql_select_db($this->dbname, $conn))) {
		    $this->ERROR = "\r\n". "ERROR : Can't connected to server";
			return false;
		}else{
			$this->CONNECT = $conn;
			return true;
		}
	}
	
	
	########################################################
	# Function:    RunSQL
	# Parameters:  $sql (query statement)
	# description : Function to execute the standard 
	#				SQL Query (DELETE & UPDATE)
	######################################################
	function RunSQL($sql){
	if ($this->CONNECT) {
	    $result = mysql_query($sql);
		mysql_free_result($result);
		return true;	
	}else{
		$this->ERROR = "<center><font size=2 color=red><b>SQL ERROR :</b> <br>".mysql_error()."</font></center>";
		return false;
	}
	}
	
	###########################################
	# Function:    GetRecord
	# Parameters:  $sql (query statement)
	# description : Function to get the data from database
	###########################################
	function GetRecord($sql){
		$db = $this->connectDB();
		$rs = mysql_query ($sql) or die('<center><font size=2 color=red><b>SQL ERROR :</b> <br>'.$sql.'<br>'.mysql_error().'</font></center>'); 
		//$arr = array();
		$Row = array();
		$y=0;
		# Get Count of Field
		while ($fld < mysql_fetch_field($rs)){
			$y++;
		}
		$x=0;
		# Get the Record
		while ($Row = mysql_fetch_row($rs)){
			for ($i=0;$i<=$y;$i++){
				$arr[$x][$i] = $Row[$i];
			}
			$x++;
		}
		@mysql_free_result($this->rs);
		return $arr;
	}
	
	###########################################
	# Function:    CloseConnection
	# Parameters:  N/A
	# Return Type: boolean
	# Description: closes connection to the database
	###########################################
	function closeDB() {
	if (mysql_close($this->CONNECT)) {
	    return true;
	}else{
		$this->ERROR = "\r\n". "Unable to close the connection";
		return false;
	}
	}

}
?>
Return current item: mydna