/** * @param array $_value * @return string */ public function insert(array $_value) { /* ## LOGGER ## */ if (isset($this->logger)) { $this->logger->DEBUG('insert'); } if (empty($_value)) { throw new UndefinedException('null'); } // HANDLING MIT NULL WERTEN // AUCH IN UPDATE $data = ''; $values = ''; foreach ($_value as $key => $value) { $data .= ',`' . $this->connection->escape($key) . '`'; if ($value == 'NULL') { $values .= ',NULL'; } else { $values .= ',\'' . $this->connection->escape($value) . '\''; } } $data = substr($data, 1); $values = substr($values, 1); $table = $this->connection->escape($this->table); $primary = $this->connection->escape($this->primary); if (array_key_exists($primary, $_value) || empty($primary)) { $sql = 'INSERT INTO `' . $table . '` (' . $data . ') VALUES (' . $values . ');'; } else { $sql = 'INSERT INTO `' . $table . '` (`' . $primary . '`, ' . $data . ') VALUES (NULL, ' . $values . ');'; } $result = $this->connection->send($sql); // bedingungen prüfen // undefined row field table .. // fehlermeldungen verschönern if ($this->connection->getAffectedRows() <= 0) { throw new SQLStatementException('invalid statement ' . $sql); } if (array_key_exists($primary, $_value)) { return $_value[$this->primary]; } else { if (empty($primary)) { return 0; } else { return $this->connection->getInsertID(); } } }
public function save() { $oCon = new Connection(); if ($this->iPostID == 0) { $sSQL = "INSERT INTO tbposts (PostContent, TopicID, MemberID) VALUES (\n '" . $this->sPostContent . "',\n '" . $this->iTopicID . "',\n '" . $this->iMemberID . "')"; $bResult = $oCon->query($sSQL); if ($bResult == true) { $this->iPostID = $oCon->getInsertID(); } else { die($sSQL . " did not run"); } } else { $sSQL = 'UPDATE tbposts SET Active = ' . $this->iActive . ' WHERE PostID=' . $this->iPostID; $bResult = $oCon->query($sSQL); } $oCon->close(); }
public function save() { $oCon = new Connection(); if ($this->iCategoryID == 0) { $sSQL = 'INSERT INTO tbcategory (CategoryName, CategoryDesc) VALUES( "' . $this->sCategoryName . '", "' . $this->sCategoryDesc . '")'; $bResult = $oCon->query($sSQL); if ($bResult == true) { $this->iCategoryID = $oCon->getInsertID(); } else { die($sSQL . " did not run"); } } else { $sSQL = 'UPDATE tbcategory SET Active = ' . $this->iActive . ' WHERE CategoryID=' . $this->iCategoryID; $bResult = $oCon->query($sSQL); } $oCon->close(); }
public function save() { $oCon = new Connection(); if ($this->iCustomerID == 0) { $sSQL = "INSERT INTO tbcustomer (Name, Address, Phone, Email, Password) \n\t\t\t\tVALUES ('" . $this->sName . "', '" . $this->sAddress . "', '" . $this->sPhone . "', '" . $this->sEmail . "', '" . $this->sPassword . "')"; $bResult = $oCon->query($sSQL); if ($bResult == true) { $this->iCustomerID = $oCon->getInsertID(); } else { die($sSQL . " Did not run"); } } else { $sSQL = "UPDATE tbcustomer \n\t\t\t\t\tSET Name = '" . $this->sName . "',\n\t\t\t\t\t \tAddress = '" . $this->sAddress . "',\n\t\t\t\t\t \tPhone = '" . $this->sPhone . "',\n\t\t\t\t\t \tEmail = '" . $this->sEmail . "',\n\t\t\t\t\t \tPassword = '******'\n\t\t\t\t\t \tWHERE CustomerID = " . $this->iCustomerID; $bResult = $oCon->query($sSQL); if ($bResult == false) { die($sSQL . " Did not run"); } } $oCon->close(); }
public function save() { $oCon = new Connection(); if ($this->iMemberID == 0) { $sSQL = "INSERT INTO tbmember\n (MemberName, MemberPassword, MemberEmail) VALUES ('" . $this->sMemberName . "',\n '" . $this->sMemberPassword . "',\n '" . $this->sMemberEmail . "')"; $bResult = $oCon->query($sSQL); if ($bResult == true) { $this->iMemberID = $oCon->getInsertID(); } else { die($sSQL . " did not run"); } } else { $sSQL = "UPDATE tbmember SET MemberName = '" . $this->sMemberName . "'WHERE MemberID = " . $this->iMemberID; $bResult = $oCon->query($sSQL); if (bResult == false) { die($sSQL . " did not run"); } } $oCon->close(); }
public function save() { $oCon = new Connection(); if ($this->iTopicID == 0) { $sSQL = 'INSERT INTO tbtopics (TopicSubject, TopicDesc, CategoryID, MemberID) VALUES( "' . $this->sTopicSubject . '", "' . $this->sTopicDesc . '", "' . $this->iCategoryID . '", "' . $this->iMemberID . '")'; $bResult = $oCon->query($sSQL); if ($bResult == true) { $this->iTopicID = $oCon->getInsertID(); } else { die($sSQL . " did not run"); } } else { $sSQL = 'UPDATE tbtopics SET Active = ' . $this->iActive . ' WHERE TopicID=' . $this->iTopicID; $bResult = $oCon->query($sSQL); } $oCon->close(); }