/** * Test loadObject method * * @return void * * @since 11.4 */ public function testLoadObject() { $query = $this->object->getQuery(true); $query->select('*'); $query->from('jos_dbtest'); $query->where('description=' . $this->object->quote('three')); $this->object->setQuery($query); $result = $this->object->loadObject(); $objCompare = new stdClass(); $objCompare->id = 3; $objCompare->title = 'Testing3'; $objCompare->start_date = '1980-04-18 00:00:00'; $objCompare->description = 'three'; $this->assertThat($result, $this->equalTo($objCompare), __LINE__); }
/** * This global function loads the first row of a query into an object * * 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 object The address of variable */ function loadObject(&$object) { if ($object != null) { if (!($cur = $this->query())) { return false; } if ($array = mysqli_fetch_assoc($cur)) { mysqli_free_result($cur); mosBindArrayToObject($array, $object, null, null, false); return true; } else { return false; } } else { $object = parent::loadObject(); return $object; } }
/** * Loads the first row of a query into an object * * @throws SPException * @return stdObject */ public function loadObject() { try { $r = $this->db->loadObject(); $this->count++; } catch (Exception $e) { } if ($this->db->getErrorNum()) { throw new SPException($this->db->stderr()); } else { if ($r && is_object($r)) { $attr = get_object_vars($r); foreach ($attr as $property => $value) { if (is_string($value) && strstr($value, '"')) { $r->{$property} = class_exists('SPLang') ? SPLang::clean($value) : $value; } } } return $r; } }
/** * Query to database * @param JBDatabaseQuery $select * @param bool $isOne * @param bool $toArray * @return mixed */ protected function _query(JBDatabaseQuery $select, $isOne = false, $toArray = false) { //jbdump::sql($select); $selectSql = (string) $select; $this->app->jbdebug->sql($selectSql); $this->_db->setQuery($selectSql); if (!$toArray) { if ((bool) $isOne) { $result = $this->_db->loadObject(); } else { $result = $this->_db->loadObjectList(); } } else { if ((bool) $isOne) { $result = $this->_db->loadAssoc(); } else { $result = $this->_db->loadAssocList(); } } return $result; }