class DB
{
private $link;
function connectDB($dbhost, $dbuser, $dbpw, $dbname="", $pconnect = 1)
{
if($pconnect)
{
if(!$this->link = mysql_pconnect($dbhost, $dbuser, $dbpw))
{
$this->mysqlErrorMessage('Can not connect to MySQL');
}
}
else
{
if(!$this->link = mysql_connect($dbhost, $dbuser, $dbpw))
{
$this->mysqlErrorMessage('Can not connect to MySQL');
}
}
if(!empty($dbname))
{
mysql_select_db($dbname,$this->link);
}
mysql_query("set names 'gb2312'",$this->link);
}
function selectDB($dbName)
{
mysql_select_db($dbName,$this->link);
}
function query($sql)
{
if(!($query = mysql_query($sql,$this->link)))
{
$this->mysqlErrorMessage('SQL Error',$sql);
}
return $query;
}
function mysqlErrorMessage($errorTitle,$errorContent)
{
echo $errorTitle." : ".$errorContent."
";
}
function fetchArray($query)
{
return mysql_fetch_array($query);
}
function fetchObject($query)
{
return mysql_fetch_object($query);
}
function closeDB()
{
mysql_close($this->link);
}
}
$db=new DB();
?>