Server = SQL_SERVER; $this->Username = SQL_USERNAME; $this->Password = SQL_PASSWORD; $this->DBName = SQL_DBNAME; $this->SelectedRecords = 0; $this->ModifiedRecords = 0; $this->RecordSet = FALSE; $this->FetchedRow = FALSE; $this->Rights = array(); $this->LogEnabled = FALSE; $this->FileLogEnabled = FALSE; $this->LogData = array(); $this->fhandle = NULL; if ($this->LogEnabled){ //$this->LogData[] = time() . " sql: Class constructed"; if ($this->FileLogEnabled){ $this->fhandle = fopen("sqlLog.txt", "w"); } } $this->Connection = mysql_connect($this->Server, $this->Username, $this->Password); if(_PG_ == 'export'){ mysql_set_charset('utf8'); } register_shutdown_function(array(&$this, 'danDestructor')); } function danDestructor() { mysql_close($this->Connection); if ($this->LogEnabled){ //$this->LogData[] = time() . " sql: Class destroyed"; //$this->LogData[] = time() . " sql: " . count($this->LogData) . " log entries counted"; if ($this->FileLogEnabled){ fwrite($this->fhandle, print_r($this->LogData, 1)); fclose($this->fhandle); } } } function Log($argSQL, $argDB, $argAddString) { $this->LogData[] = time() . " $argDB: " . $argSQL . " (" . $argAddString . ")"; } function sqlModify($argSQL, $argDB = NULL){ if (is_null($argDB)){ $argDB = $this->DBName; } if (mysql_select_db($argDB)){ if (mysql_query($argSQL, $this->Connection)){ $this->ModifiedRecords = mysql_affected_rows(); $this->Log($argSQL, $argDB, $this->ModifiedRecords); return TRUE; }else{ $this->Log($argSQL, $argDB, mysql_error()); return FALSE; } }else{ $this->Log($argSQL, $argDB, mysql_error()); return FALSE; } } function sqlInsertID($argSQL, $argDB = NULL){ if (is_null($argDB)){ $argDB = $this->DBName; } if (mysql_select_db($argDB)){ if (mysql_query($argSQL, $this->Connection)){ $this->ModifiedRecords = mysql_affected_rows(); $this->Log($argSQL, $argDB, $this->ModifiedRecords); return mysql_insert_id(); }else{ $this->Log($argSQL, $argDB, mysql_error()); return 0; } }else{ $this->Log($argSQL, $argDB, mysql_error()); return 0; } } function sqlSelect($argSQL, $argDB = NULL){ if (is_null($argDB)){ $argDB = $this->DBName; } if (mysql_select_db($argDB)){ $this->RecordSet = mysql_query($argSQL, $this->Connection); if ($this->RecordSet){ $this->SelectedRecords = mysql_num_rows($this->RecordSet); $this->Log($argSQL, $argDB, $this->SelectedRecords); return TRUE; }else{ $this->Log($argSQL, $argDB, mysql_error()); return FALSE; } }else{ $this->Log($argSQL, $argDB, mysql_error()); return FALSE; } } function sqlCount($argTableName, $argSQL = NULL, $argDB = NULL){ if (is_null($argDB)){ $argDB = $this->DBName; } if (is_null($argSQL)){ $argSQL = ""; }else{ $argSQL = " " . $argSQL; } $argSQL = "SELECT COUNT(*) AS count FROM " . $argTableName . $argSQL; if (mysql_select_db($argDB)){ $rs = mysql_query($argSQL, $this->Connection); if ($row = mysql_fetch_array($rs)){ $this->Log($argSQL, $argDB, $row[count]); return $row[count]; }else{ return 0; } } } function sqlFetchRow($argSQLData){ $this->FetchedRow = mysql_fetch_array($argSQLData, MYSQL_ASSOC); if ($this->FetchedRow){ return TRUE; }else{ return FALSE; } } function getDate(){ return date("Y-m-d"); } function getTime(){ return date("H:i:s"); } function getAccDate(){ return date("d.m.Y"); } function getKeyVal($argAssocArray, $argCompareKey){ foreach ($argAssocArray as $key => $val){ if ($key == $argCompareKey){ return $val; } } } function getSelBox($argAssocArray, $argCompareKey, $argDefValue = NULL){ $strOption = NULL; $varKey = NULL; foreach ($argAssocArray as $key => $val){ if ($key == $argCompareKey){ $varKey = $key; } } if ($argDefValue !== NULL){ if ($varKey === NULL){ $varKey = $argDefValue; } } foreach ($argAssocArray as $key => $val){ if ($key == $varKey){ $strSelected = ' selected="selected"'; }else{ $strSelected = NULL; } $strOption .= ''; } return $strOption; } } ?>