Location: PHPKode > scripts > phpMysqlSessions > phpmysqlsessions/_class.mysql.php
This is a slimmed-down version of my MySQL class so that you can try this out
before getting your head too far into the mysql functionality. This chopped
version of the class has all the functions that are needed by my session class.
Last Edited: 2/14/2001 4:29PM by Justin Koivisto [Koivi Media]


class mysql_class{
	# Constructor
	function mysql_class($user="phpuser",$pass="php",$host="localhost"){
		$this->id=@mysql_pconnect($this->host,$this->user,$this->pass) or
			mysql_ErrorMsg("Unable to connect to mysql server: $this->host");

	# Select or change databases
	function SelectDB($db){
		@mysql_select_db($db,$this->id) or
			mysql_ErrorMsg("Unable to select database: $db");

	# Update elements in database
	function Update($query){
		$this->result=@mysql_query($query,$this->id) or
			mysql_ErrorMsg("Unable to perform update: $query");

	# Insert row into a table
	function Insert($query){
		$this->result=@mysql_query($query,$this->id) or
			mysql_ErrorMsg("Unable to perform insert: $query");

	# Single element return query
	function QueryItem($query){
		$this->result=@mysql_query($query,$this->id) or
			mysql_ErrorMsg("Unable to perform query: $query");
		$this->data=@mysql_fetch_array($this->result) or
			mysql_ErrorMsg("Unable to fetch data from query: $query");

	# Use if checking for empty query result returns 0 if empty,
	# and 1 if there is at least one result
	function Exists($query){
		if(@mysql_num_rows($this->result)) return 1;
		else return 0;
} # End of class

# MySQL error message function
function mysql_ErrorMsg($msg){
	# Get out of html constraints so we can see the message

	# Display the error message
	$text ="<font color=\"#ff0000\" size=+2><p>Error: $msg :";
	$text .= mysql_error();
	$text .= "</font>\n";

Return current item: phpMysqlSessions