<?
// Utility functions available to the plugin itself

// called like this: $nResult = dbRunQuery("INSERT INTO plugin_addThis VALUES ('0','Email','Email','1');");
function dbRunQuery($nQuery){
	global $DBName,$Link;
	if(!$nQuery){ return; }
	mysql_select_db($DBName);
	$nResult = mysql_query($nQuery, $Link);
	return $nResult;
}
// called like this:
// dbTableCreate("addThis",
//	"`nID` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
//	`nCode` VARCHAR( 50 ) NOT NULL,
//	`nDesc` TEXT NOT NULL,
//	`nActive` TINYINT NOT NULL DEFAULT '0'"
//);
function dbTableCreate($nTable="",$nColumnSQL){
	global $DBName,$Link,$nPluginID;
	if(!$nTable || !$nColumnSQL || !$nPluginID){ return; }
	$nTable = $nPluginID."_".$nTable;
	$Query = "CREATE TABLE `$nTable`($nColumnSQL) TYPE=MyISAM AUTO_INCREMENT=1;";
	mysql_select_db($DBName);
	mysql_query($Query, $Link);
}
// called like this: if(!dbTableExists("addThis")){ }
function dbTableExists($nTable=""){
	global $DBName,$nPluginID;
	if(!$nTable || !$nPluginID){ return; }
	$nTable = $nPluginID."_".$nTable;
	$nTableARRAY = array();
	mysql_select_db($DBName);
	$Query = "SHOW TABLES FROM $DBName";
	$result = mysql_query($Query);
	while ($Row = mysql_fetch_array($result)){
		if($Row["0"]==$nTable){ return true; }
	}
	return false;
}
?>