english/libraries/joomla/database/database.php
/**
	 * Updates a row in a table based on an object's properties.
	 *
	 * @param   string  $table   The name of the database table to update.
	 * @param   object  $object  A reference to an object whose public properties match the table fields.
	 * @param   string  $key     The name of the primary key.
	 * @param   bool    $nulls   True to update null fields or false to ignore them.
	 *
	 * @return  bool    True on success.
	 *
	 * @since   11.1
	 * @throws  DatabaseException
	 */
Updates a row in a table based on an object's properties.
@param   string  $table   The name of the database table to update.
@param   object  $object  A reference to an object whose public properties match the table fields.
@param   string  $key     The name of the primary key.
@param   bool    $nulls   True to update null fields or false to ignore them.

@return  bool    True on success.


Updates a row in a table based on an object ' s properties . @param string $table The name of the database table to update . @param object $object A reference to an object whose public properties match the table fields . @param string $key The name of the primary key . @param bool $nulls True to update null fields or false to ignore them . @return bool True on success .
public function updateObject($table, & $object, $key, $nulls=false)
	{
		$fields = array();
		$where  = '';
		$statement = 'UPDATE '.$this->quoteName($table).' SET %s WHERE %s';
		foreach (get_object_vars($object) as $k => $v)
		{
			if (is_array($v) or is_object($v) or $k[0] == '_') {
				continue;
			}
			if ($k == $key) {
				$where = $this->quoteName($k).'='.$this->quote($v);
				continue;
			}
			if ($v === null) {
				if ($nulls) {
					$val = 'NULL';
				}
				else {
					continue;
				}
			}
			else {
				$val = $this->isQuoted($k) ? $this->quote($v) : (int) $v;
			}
			$fields[] = $this->quoteName($k).'='.$val;
		}
		if (empty($fields)) {
			return true;
		}
		$this->setQuery(sprintf($statement, implode(",", $fields) , $where));
		return $this->query();
	}
public function updateObject ( $ table , & $ object , $ key , $ nulls = false ) { $ fields = array ( ) ; $ where = '' ; $ statement = 'UPDATE ' . $ this -> quoteName ( $ table ) . ' SET %s WHERE %s' ; foreach ( get_object_vars ( $ object ) as $ k => $ v ) { if ( is_array ( $ v ) or is_object ( $ v ) or $ k [ 0 ] == '_' ) { continue ; } if ( $ k == $ key ) { $ where = $ this -> quoteName ( $ k ) . '=' . $ this -> quote ( $ v ) ; continue ; } if ( $ v === null ) { if ( $ nulls ) { $ val = 'NULL' ; } else { continue ; } } else { $ val = $ this -> isQuoted ( $ k ) ? $ this -> quote ( $ v ) : ( int ) $ v ; } $ fields [ ] = $ this -> quoteName ( $ k ) . '=' . $ val ; } if ( empty ( $ fields ) ) { return true ; } $ this -> setQuery ( sprintf ( $ statement , implode ( " , " , $ fields ) , $ where ) ) ; return $ this -> query ( ) ; }
Updates a row in a table based on an object's properties.
Updates a row in a table based on an object ' s properties .
// Initialise variables. // Create the base update statement. // Iterate over the object variables to build the query fields/value pairs. // Only process scalars that are not internal fields. // Set the primary key to the WHERE clause instead of a field to update. // Prepare and sanitize the fields and values for the database query. // If the value is null and we want to update nulls then set it. // If the value is null and we do not want to update nulls then ignore this field. // The field is not null so we prep it for update. // Add the field to be updated. // We don't have any fields to update. // Set the query and execute the update.