/******************************
* dbClass Bokkiewokkie styley
* For frontend of NL20
*
* $LastChangedBy: tobias $
* $LastChangedDate: 2007-07-05 17:45:55 +0200 (Thu, 05 Jul 2007) $
* $Rev: 354 $
*
* By: Tobias Beuving (tobias@gadgets.nl)
*
********************************/
class dbClass {
/* public: connection parameters */
/* Connecting, selecting database */
var $pHost = "insideoutside.nl";
var $pDatabase = "lievestrocms";
var $pUser = "lievestro";
var $pPassword = "boomstam39";
var $pResourceLink = 0;
var $pIsConnected = false;
var $pOperationOutput = "";
var $pRecordsInResult = Array();
var $pNumRows = 0;
function mConnect() {
$tmpOutput = true; //default true, otherwise when error occurs: false
$this->pIsConnected = true;
$this->pResourceLink = mysql_connect($this->pHost, $this->pUser, $this->pPassword);
if (!$this->mNoError()) {
$this->pIsConnected = false;
$tmpOutput = false;
}
return $tmpOutput;
}
function mSelect() {
mysql_select_db($this->pDatabase, $this->pResourceLink);
return $this->mNoError();
}
// MySQL 4.0> gets the total amount of rows without the limit x,y
function mGetFoundRows() {
$tmpSQL = "SELECT FOUND_ROWS() AS total_rows";
$result = mysql_query($tmpSQL, $this->pResourceLink);
$tmpRecordA = mysql_fetch_array($result, MYSQL_ASSOC);
return $tmpRecordA['total_rows'];
}
// private
function mNoError() {
$tmpOutput = true; //default true, otherwise when error occurs: false
if (mysql_errno($this->pResourceLink)>0) {
$this->pOperationOutput .= mysql_errno($this->pResourceLink) . ": " . mysql_error($this->pResourceLink) . "
";
$tmpOutput = false;
}
return $tmpOutput;
}
function mCleanStringForDb($stringIn) {
$stringIn = trim($stringIn);
if ((substr($stringIn,0,1) == "\"") && (substr($stringIn,-1,1) == "\"")) {
$stringIn = trim($stringIn);
$stringIn = substr($stringIn,1,strlen($stringIn)-2);
if (substr($stringIn,-2) == "\"\"") {
$stringIn = substr($stringIn,0,strlen($stringIn)-1);
}
}
return addslashes($stringIn);
}
// function added 23 nov 2006
function mGetInsertId() {
return mysql_insert_id ($this->pResourceLink);
}
// function added 3 dec 2006
function mGetNumRows() {
return $this->pNumRows;
}
// function added 12 mei 2006
function mExecuteQuery($SQLIn) {
$this->pLastQuery = $SQLIn;
$result = mysql_query($this->pLastQuery,$this->pResourceLink);
$this->pRecordsInResult = Array();
if (mysql_errno($this->pResourceLink)>0) {
$this->pError = true;
print "
"; print $this->mGetErrorInfo(); print ""; } else { $this->pError = false; while (@$tmpRecordA = mysql_fetch_array($result, MYSQL_ASSOC)) { $this->pRecordsInResult[] = $tmpRecordA; } if (strpos(strtolower($SQLIn), "select") !== false ) { $this->pNumRows = mysql_num_rows($result); } } @mysql_free_result($result); /* print "
"; print $SQLIn; print_r($tmpOutput); print ""; */ return $this->pRecordsInResult; } function mGetErrorInfo() { return mysql_errno($this->pResourceLink) . ": " . mysql_error($this->pResourceLink) . " query:".$this->pLastQuery."
"; print_r($recordIn); print ""; */ foreach($recordIn AS $key=>$value) { if (is_array($value) && !$forceArrayAsValueIn) { print "Error: baseClass.mRender: trying to render data with template:".$templateIn; print "
"; print_r($recordIn); print ""; print "Halted at key:".$key." value:"; print "
"; print_r($value); print ""; exit; } } $tmpHTML = ""; if ($recordIn == 0) { $recordIn = Array(); } $tmpSmartyO = baseClass::mGetSmarty(); foreach($recordIn AS $key=>$value) { $tmpSmartyO->assign($key, $value); } echo $tmpSmartyO->fetch($templateIn); } function mRenderMail($recordIn = null,$templateIn, $forceArrayAsValueIn = false) { /* print "
"; print_r($recordIn); print ""; */ foreach($recordIn AS $key=>$value) { if (is_array($value) && !$forceArrayAsValueIn) { print "Error: baseClass.mRender: trying to render data with template:".$templateIn; print "
"; print_r($recordIn); print ""; print "Halted at key:".$key." value:"; print "
"; print_r($value); print ""; exit; } } $tmpHTML = ""; if ($recordIn == 0) { $recordIn = Array(); } $tmpSmartyO = baseClass::mGetSmarty(); foreach($recordIn AS $key=>$value) { $tmpSmartyO->assign($key, $value); } return $tmpSmartyO->fetch($templateIn); } function mRenderMultiple($recordsIn = null,$templateIn) { if ($recordsIn == null) { $recordsIn = Array(); } $tmpHTML = ""; foreach($recordsIn AS $tmpRecord) { $tmpSmartyO = baseClass::mGetSmarty(); foreach($tmpRecord AS $key=>$value) { $tmpSmartyO->assign($key, $value); } $tmpHTML .= $tmpSmartyO->fetch($templateIn); } return $tmpHTML; } // maakt een JSON (Javascript object notation) string van een array function mArrayToJSON($tmpArrayIn) { $tmpRecords = Array(); foreach ($tmpArrayIn AS $key=>$value) { $tmpValueString = ""; if (is_array($value)) { $tmpPropertiesB = Array(); foreach ($value AS $key2=>$value2) { $tmpPropertiesB[] = '"'.$key2.'": "'.$value2.'"'; } $tmpValueString = "{".implode(",", $tmpPropertiesB)."}"; } else { $tmpValueString = '"'.$value.'"'; } //$tmpPropertiesA[] = '"'.$key.'": '.$tmpValueString; $tmpRecords[] = $tmpValueString; } $tmpPropertiesString = implode(",", $tmpRecords); $tmpJSON = '['. $tmpPropertiesString . ']'; return $tmpJSON; } /** * Displays a debug message * @param mixed de te printen info (array of string) */ function mTrace($msgIn) { print "
";
if (is_array($msgIn)) {
print_r($msgIn);
} else {
print $msgIn;
}
print "