Example #1
0
 /**
  * retrieve an object from the database, based on. use in child classes
  *
  * @param int $id ID
  *
  * @return mixed object if id exists, false if not
  * @access public
  */
 public function &get($id)
 {
     $id = intval($id);
     if ($id > 0) {
         $sql = $this->_selectQuery(new Criteria($this->_idfield, $id));
         if (!($result = $this->_db->query($sql))) {
             return false;
         }
         $numrows = $this->_db->getRowsNum($result);
         if ($numrows == 1) {
             $obj = new $this->classname($this->_db->fetchArray($result));
             return $obj;
         }
     }
     return false;
 }
Example #2
0
 /**
  * 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);
         }
     }
 }