本文整理汇总了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;
}
}
示例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);
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
}