<?
/*
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]
*/
$MYSQL_CLASS_INC=true;
class mysql_class{
# Constructor
function mysql_class($user="phpuser",$pass="php",$host="localhost"){
$this->user=$user;
$this->pass=$pass;
$this->host=$host;
$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){
$this->db=$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");
$this->a_rows=@mysql_affected_rows($this->result);
}
# Insert row into a table
function Insert($query){
$this->result=@mysql_query($query,$this->id) or
mysql_ErrorMsg("Unable to perform insert: $query");
$this->a_rows=@mysql_affected_rows($this->result);
}
# Single element return query
function QueryItem($query){
$this->result=@mysql_query($query,$this->id) or
mysql_ErrorMsg("Unable to perform query: $query");
$this->rows=@mysql_num_rows($this->result);
$this->data=@mysql_fetch_array($this->result) or
mysql_ErrorMsg("Unable to fetch data from query: $query");
return($this->data[0]);
}
# Use if checking for empty query result returns 0 if empty,
# and 1 if there is at least one result
function Exists($query){
$this->result=@mysql_query($query,$this->id);
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
echo("</ul></ul></ul></dl></dl></dl></ol></ol></ol>\n");
echo("</table></table></table></script></script></script>\n");
# Display the error message
$text ="<font color=\"#ff0000\" size=+2><p>Error: $msg :";
$text .= mysql_error();
$text .= "</font>\n";
die($text);
}
?>