/** * Executes the query to load the rows and returns them * If an object is passed to this function, the returned row is bound to the existing elements of <var>object</var>. * If <var>object</var> has a value of null, then all of the returned query fields returned in the object. * * @param \stdClass|null $object IN+OUT: The address of variable * @return boolean True if the object got loaded */ public function &queryLoadObject(&$object) { $sql = $this->_buildSQLquery(); $this->_db->setQuery($sql); $result = $this->_db->loadObject($object); if ($result) { if (!$object instanceof TableInterface) { $object->_tbl = $this->_table; } } else { if (null != ($errormsg = $this->_db->getErrorMsg())) { trigger_error('SQLXML::queryLoadObject: error returned: ' . $errormsg, E_USER_NOTICE); } } return $result; }
/** * Loads a row from the database into $this object by primary key or specific (typed) keys * E.g. load->( array( 'name' => 'Smith', 'age' => 25 ) ). * * @param int|array $keys [Optional]: Primary key value or array of primary keys to match. If not specified, the value of current key is used * @return boolean Result from the database operation * * @throws \InvalidArgumentException * @throws \RuntimeException * @throws \UnexpectedValueException */ public function load($keys = null) { $where = $this->getSafeWhereStatements($keys); if (empty($where)) { return false; } //BB fix : resets default values to all object variables, because NULL SQL fields do not overide existing variables ! TODO: May be removed for 2.0! $primaryKeys = array_keys($this->getPrimaryKeysTypes()); $class_vars = get_class_vars(get_class($this)); foreach ($class_vars as $name => $value) { if (!in_array($name, $primaryKeys) && $name != "_db" && $name != "_tbl" && $name != "_tbl_key" && substr($name, 0, 10) != "_history__") { $this->{$name} = $value; } } //end of BB fix. $this->reset(); $query = "SELECT *" . "\n FROM " . $this->_db->NameQuote($this->_tbl) . "\n WHERE " . implode(' AND ', $where); $this->_db->setQuery($query); return $this->_db->loadObject($this); }