当前位置: 首页>>代码示例>>PHP>>正文


PHP JDatabase::loadAssoc方法代码示例

本文整理汇总了PHP中JDatabase::loadAssoc方法的典型用法代码示例。如果您正苦于以下问题:PHP JDatabase::loadAssoc方法的具体用法?PHP JDatabase::loadAssoc怎么用?PHP JDatabase::loadAssoc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JDatabase的用法示例。


在下文中一共展示了JDatabase::loadAssoc方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: load

 /**
  * Loads a row from the database and binds the fields to the object properties
  *
  * @access	public
  * @param	mixed	Optional primary key.  If not specifed, the value of current key is used
  * @return	boolean	True if successful
  */
 function load()
 {
     $k = $this->_tbl_key;
     $where_pk = array();
     $this->reset();
     $query = $this->_db->getQuery(true);
     $query->select(' * ');
     $query->from(' ' . $this->_db->quoteName($this->_tbl) . ' ');
     // check whether all fields are filled and build where statement
     for ($i = 0; $i < count($k); $i++) {
         if ($this->{$k}[$i] === null) {
             return false;
         } else {
             $query->where(' ' . $this->_db->quoteName($k[$i]) . ' = ' . $this->_db->Quote($this->{$k}[$i]) . ' ');
         }
     }
     $this->_db->setQuery($query);
     if ($result = $this->_db->loadAssoc()) {
         return $this->bind($result);
     } else {
         if ($error = $this->_db->getErrorMsg()) {
             throw new JException($error);
         }
         return false;
     }
 }
开发者ID:Lothurm,项目名称:J3.x,代码行数:33,代码来源:JMFPKtable.php

示例2: load

 /**
  * Method to load a row from the database by primary key and bind the fields
  * to the JTable instance properties.
  *
  * @param   mixed    $keys   An optional primary key value to load the row by, or an array of fields to match.  If not
  * set the instance property value is used.
  * @param   boolean  $reset  True to reset the default values before loading the new row.
  *
  * @return  boolean  True if successful. False if row not found or on error (internal error state set in that case).
  *
  * @link    http://docs.joomla.org/JTable/load
  * @since   11.1
  */
 public function load($keys = null, $reset = true)
 {
     if (empty($keys)) {
         // If empty, use the value of the current key
         $keyName = $this->_tbl_key;
         $keyValue = $this->{$keyName};
         // If empty primary key there's is no need to load anything
         if (empty($keyValue)) {
             return true;
         }
         $keys = array($keyName => $keyValue);
     } elseif (!is_array($keys)) {
         // Load by primary key.
         $keys = array($this->_tbl_key => $keys);
     }
     if ($reset) {
         $this->reset();
     }
     // Initialise the query.
     $query = $this->_db->getQuery(true);
     $query->select('*');
     $query->from($this->_tbl);
     $fields = array_keys($this->getProperties());
     foreach ($keys as $field => $value) {
         // Check that $field is in the table.
         if (!in_array($field, $fields)) {
             $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_CLASS_IS_MISSING_FIELD', get_class($this), $field));
             $this->setError($e);
             return false;
         }
         // Add the search tuple to the query.
         $query->where($this->_db->quoteName($field) . ' = ' . $this->_db->quote($value));
     }
     $this->_db->setQuery($query);
     try {
         $row = $this->_db->loadAssoc();
     } catch (RuntimeException $e) {
         $je = new JException($e->getMessage());
         $this->setError($je);
         return false;
     }
     // Legacy error handling switch based on the JError::$legacy switch.
     // @deprecated  12.1
     if (JError::$legacy && $this->_db->getErrorNum()) {
         $e = new JException($this->_db->getErrorMsg());
         $this->setError($e);
         return false;
     }
     // Check that we have a result.
     if (empty($row)) {
         $e = new JException(JText::_('JLIB_DATABASE_ERROR_EMPTY_ROW_RETURNED'));
         $this->setError($e);
         return false;
     }
     // Bind the object with the row and return.
     return $this->bind($row);
 }
开发者ID:NavaINT1876,项目名称:ccustoms,代码行数:70,代码来源:table.php

示例3: loadObject

 /**
  * 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|\stdClass  $object
  * @return boolean          Success
  *
  * @throws  \RuntimeException
  */
 public function loadObject(&$object)
 {
     if ($object === null) {
         $object = $this->_db->loadObject();
         return is_object($object);
     }
     $array = $this->_db->loadAssoc();
     if (!is_array($array)) {
         return false;
     }
     foreach (get_object_vars($object) as $k => $v) {
         if (substr($k, 0, 1) != '_') {
             if (array_key_exists($k, $array)) {
                 $object->{$k} = $array[$k];
             }
         }
     }
     return true;
 }
开发者ID:bobozhangshao,项目名称:HeartCare,代码行数:29,代码来源:CmsDatabaseDriver.php

示例4: load

 /**
  * Method builds this model based on a contact's id
  * 
  * @param integer $user_id
  * @return boolean
  */
 function load($id = null)
 {
     //reasons to fail
     if (is_null($id) || !$id) {
         return false;
     }
     if (!is_string($id)) {
         return false;
     }
     //initializing variables
     $id = addslashes($id);
     //Get the Contacts information
     $query = "SELECT * " . " FROM `" . $this->_tbl . "`" . " WHERE `id` = '{$id}'";
     $this->_db->setQuery($query);
     $result = $this->_db->loadAssoc();
     if (!$result) {
         return false;
     }
     $this->bind($result);
     //loading any custom properties
     $this->loadCustomProperties();
     return true;
 }
开发者ID:Jonathonbyrd,项目名称:Joomla-Listings,代码行数:29,代码来源:sugar_table.php

示例5: queryAssoc

 /**
  * Execute a query to the database and get the first row of the result set from the database query as an associative array
  *
  * The result returned by this method is the same as the one returned by JDatabase::loadAssoc()
  * Generally used for SELECT operations
  *
  * @param string $query The query to be executed
  *
  * @return array The first row of the result of the query
  *
  * @throws RuntimeException
  *
  * @since 1.0.0
  */
 public function queryAssoc($query)
 {
     // query database table
     $this->_database->setQuery($query);
     return $this->_database->loadAssoc();
 }
开发者ID:JBZoo,项目名称:Zoo-Changelog,代码行数:20,代码来源:database.php

示例6: loadAssoc

 /**
  * Fetch a result row as an associative array
  *
  * @return array
  */
 function loadAssoc()
 {
     if (is_callable(array($this->_db, 'loadAssoc'))) {
         return $this->_db->loadAssoc();
     } else {
         // new independant efficient implementation:
         if (!($cur = $this->query())) {
             $result = null;
         } else {
             $result = $this->m_fetch_assoc($cur);
             if (!$result) {
                 $result = null;
             }
             $this->m_free_result($cur);
         }
         return $result;
     }
 }
开发者ID:rogatnev-nikita,项目名称:cloudinterpreter,代码行数:23,代码来源:cb.database.php


注:本文中的JDatabase::loadAssoc方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。