All pastes #512926 Raw Edit

Miscellany

public text v1 · immutable
#512926 ·published 2007-05-27 01:11 UTC
rendered paste body
<?php

if (!defined('PHPRPG_MYSQL')) define('PHPRPG_MYSQL', true);

class MYSQL
{
//PUBLIC:
	// return data
	var $result;
	var $error;

	// send an unbuffered (lowcost) query to the db, disregard return
	// exept for error data.
	function command($query) {
		if (!@mysql_unbuffered_query($query,$this->connect())) {
			$this->error = mysql_error();
			return(false);
		}
		return(true);
	}

	// standard query to mysql server return the results.
	function query($query) {
		$this->result = mysql_query($query,$this->connect());
		if (!@$this->result) {
			$this->error = mysql_error();
			return(false);
		}
		return($this->result);
	}

	// clean up after object
	function flush() {
		$this->error = false;
		if (!@mysql_free_result($this->result)) {
			$this->error = mysql_error();
			return(false);
		}
		$this->result = false;
		return(true);
	}

//PRIVATE:
	// Logon information specific to this object.
	var $hostname;
	var $username;
	var $password;
	// information about the connection
	var $resourceid;
	var $database;

	// initialization function
	function MYSQL($host=false,$user=false,$pass=false,$db=false) {
		$this->hostname = $host;
		$this->username = $user;
		$this->password = $pass;
		$this->database = $db;

		$this->resourceid = false;
		$this->result = false;
	}

	// attempt to connect to the database
	function connect() {
		if (empty($this->resourceid) && !empty($this->database)) {
			$this->resourceid = mysql_pconnect($this->hostname,$this->username,$this->password);
			mysql_select_db($this->database,$this->resourceid);
		}
		return($this->resourceid);
	}
}


?>