/** * execute an SQL statement * * @param string $sql SQL statement to execute * @param bool $force true to use queryF * * @return mixed result resouce if no error, * true if no error but no result * false if error encountered. * Any error message is in $this->lastError; */ private function &execSql($sql, $force = false) { if ($force) { $result = $this->db->queryF($sql); } else { $result = $this->db->query($sql); } if (!$result) { $this->lastError = $this->db->error(); $this->lastErrNo = $this->db->errno(); } return $result; }
/** * delete object based on id * * @param object $obj {@link XoopsObject} to delete * @param bool $force override XOOPS delete protection * * @return bool deletion successful? * @access public */ public function delete(&$obj, $force = false) { if (strcasecmp($this->classname, get_class($obj)) != 0) { return false; } $sql = $this->_deleteQuery($obj); if (false != $force) { $result = $this->_db->queryF($sql); } else { $result = $this->_db->query($sql); } if (!$result) { return false; } return true; }
/** * This method allows to copy fields from one table to another * * @param array $fieldsMap Map of the fields * ex: array('oldfieldname' => 'newfieldname'); * @param string $oTableName Old Table * @param string $nTableName New Table * @param bool $dropTable Drop old Table * * @return this does not return anything */ public function copyFields($fieldsMap, $oTableName, $nTableName, $dropTable = false) { $sql = "SHOW COLUMNS FROM " . $this->db->prefix($oTableName); $result = $this->db->queryF($sql); if (($rows = $this->db->getRowsNum($result)) == count($fieldsMap)) { $sql = "SELECT * FROM " . $this->db->prefix($oTableName); $result = $this->db->queryF($sql); while ($myrow = $this->db->fetchArray($result)) { ksort($fieldsMap); ksort($myrow); $sql = "INSERT INTO `" . $this->db->prefix($nTableName) . "` " . "(`" . implode("`,`", $fieldsMap) . "`)" . " VALUES ('" . implode("','", $myrow) . "')"; $this->db->queryF($sql); } if ($dropTable) { $sql = "DROP TABLE " . $this->db->prefix($oTableName); $this->db->queryF($sql); } } }