Example #1
0
 /**
  * retrieve objects from the database
  *
  * @param object $criteria  {@link CriteriaElement} conditions to be met
  * @param bool   $id_as_key Should the department ID be used as array key
  *
  * @return array array of objects
  * @access  public
  */
 public function &getObjects($criteria = null, $id_as_key = false)
 {
     $ret = array();
     $limit = $start = 0;
     $sql = $this->_selectQuery($criteria);
     $id = $this->_idfield;
     if (isset($criteria)) {
         $limit = $criteria->getLimit();
         $start = $criteria->getStart();
     }
     $result = $this->_db->query($sql, $limit, $start);
     // if no records from db, return empty array
     if (!$result) {
         return $ret;
     }
     // Add each returned record to the result array
     while ($myrow = $this->_db->fetchArray($result)) {
         $obj = new $this->classname($myrow);
         if (!$id_as_key) {
             $ret[] = $obj;
         } else {
             $ret[$obj->getVar($id)] = $obj;
         }
         unset($obj);
     }
     return $ret;
 }
Example #2
0
 /**
  * Enter description here...
  *
  * @param string $sql
  * @param int $limit
  * @param int $start
  * @return array
  */
 function &_getObjects($sql, $limit = 0, $start = 0)
 {
     $ret = array();
     if ($result =& $this->_query($sql, $limit, $start)) {
         require_once XOOPS_ROOT_PATH . '/modules/openid/class/context.php';
         while ($row = $this->_db->fetchArray($result)) {
             $record = new Openid_Context();
             foreach ($row as $key => $value) {
                 $record->set($key, $value);
             }
             $ret[] =& $record;
             unset($record);
         }
     }
     return $ret;
 }
Example #3
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);
         }
     }
 }
Example #4
0
 /**
  * fetch the next row of a result set
  *
  * @param resource &$result as returned by query
  *
  * @return bool true if no errors and table is loaded, false if
  *               error presented. Error message in $this->lastError;
  */
 private function fetch(&$result)
 {
     return $this->db->fetchArray($result);
 }
Example #5
0
 /**
  * fetch the next row of a result set
  *
  * @param resource $result as returned by query
  *
  * @return mixed false on error
  */
 protected function fetch($result)
 {
     return $this->db->fetchArray($result);
 }