/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php Class DataConnection { var $oConn; var $oDB; var $oCurrentResource; var $aResultSet; var $bResultsFound; function DataConnection() { $this->bResultsFound = FALSE; } function query($sSQL, $bDebugMode = FALSE) { if ($bDebugMode) { echo $sSQL."<br />"; exit; } if ($this->getNumberOfRows() == 0) { return false; } $this->setResultSet($this->getCurrentResource()); return true; } function getNumberOfRows() { $iRows = 0; $oResource = $this->getCurrentResource(); } return $iRows; } function selectInfo($sSQL, $bDebugMode = FALSE) { $aReturn = FALSE; $this->query($sSQL, $bDebugMode); if ($this->getNumberOfRows() > 0) { $aReturn = $this->getResultSet(); } return $aReturn; } function lastId() { } function closeConnection() { } function createSQLString($sInput) { return $sInput; } function logToDatabaseViaArray($aFieldInfo, $sTableName, $sSQLConstraints = "", $sMethod = "INSERT") { $sFields = ""; $sValues = ""; if ($sMethod == "UPDATE") { $sSQL = "UPDATE ".$sTableName." SET [** UPDATES **] ".$sSQLConstraints; $sUpdateString = ""; foreach($aFieldInfo as $sKey => $sValue) { $sValue = $this->createSQLString($sValue); } $sUpdateString .= $sKey . " = ".$sValue.", "; } $this->query($sSQL); } else { $sSQL = "INSERT INTO ".$sTableName." ([** FIELDS **]) VALUES ([** VALUES **])"; foreach($aFieldInfo as $sKey => $sValue) { $sValue = $this->createSQLString($sValue); } $sFields .= $sKey . ", "; $sValues .= $sValue . ", "; } $this->query($sSQL); } } function fetchResultsByQuery($sSQL, $bDebugMode = FALSE) { $this->query($sSQL, $bDebugMode); return $this->getResultSet(); } function getInsertId() { } function destroyCurrentResource() { $oResource =& $this->getCurrentResource(); } } // MUTATORS & ACCESSORS function setCurrentResource($oNewResource) { $this->oCurrentResource = $oNewResource; } function getCurrentResource() { return $this->oCurrentResource; } function setResultSet($oNewRecordSet) { $iLoop = 0; $this->aResultSet[$iLoop][$key] = $val; } $iLoop++; } $this->setResultFound(TRUE); } else { $this->setResultFound(FALSE); } } function getResultSet() { return $this->aResultSet; } else { return FALSE; } } function getResultRow($iRow=0) { return $this->aResultSet[$iRow]; } else { return FALSE; } } function setResultFound($bNewStatus) { $this->bResultsFound = $bNewStatus; } function getResultFound() { return $this->bResultsFound; } } // END CLASS ?>