Ejemplo n.º 1
0
 /**
  * Fill collecton with models from database founded by $condition, ordered by $order, limited by $limit count
  *
  * @param  string	$condition
  * @param  string	$order
  * @param  integer	$limit
  * @return MantellaCollection
  */
 public function dbLoad($condition = null, $order = null, $limit = null)
 {
     $this->clear();
     $sql = $this->getModel()->_getSelectQuery_(null, $condition, $order, $limit);
     if ($this->_SQL_DEBUG) {
         die($sql);
     }
     $res = $this->_db->execSQL($sql);
     if (is_array($res)) {
         // if records exists
         foreach ($res as $index => $record) {
             $new_model = clone $this->getModel();
             $new_model->fill($record);
             $this->add($new_model);
         }
     }
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Function only for private use inside class
  */
 private function _selectModelFromDatabase($id)
 {
     $this->clear();
     $sql = $this->_getSelectQuery_($id);
     if ($this->_SQL_DEBUG) {
         die($sql);
     }
     $res = $this->_DBLINK->execSQL($sql);
     if ($res === false) {
         $err = $this->_DBLINK->getLastError();
         return $this->_setError($err['text']);
     }
     if ($res === false) {
         $error = $this->_DBLINK->getLastError();
         return $this->_setError($error['text']);
     }
     if (is_array($res) && isset($res[0])) {
         $this->fill($res[0]);
     }
     return $this->_setError(null);
 }