Documentation Menu

1.5 Template Project

The Joomla! Documentation Working Group is running a project to develop detailed reference and tutorial material on Joomla! 1.5 templates.  There is a project page on the documentation wiki where you can see the work in progress and help us by contributing your knowledge.

Who's Online

We have 2 guests online

Help Site License

The Joomla! Help Site content is copyright © 2005 - 2008 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution NonCommercial ShareAlike 2.5. Some parts of this website may be subject to other licenses.
Home arrow Manual arrow 11. API Reference arrow [REVIEW] database->updateObject

[REVIEW] database->updateObject PDF Print E-mail

Last reviewed: Not reviewed
phpDocumentor

database->updateObject

Updates a database table row using data contained in an object.  Returns false if the update failed; otherwise it returns the updated table row.

Syntax

object updateObject ( string $table, object &$object, string $keyname [, boolean $updateNulls ] )

$table
is the name of the database table.
$object
is an object containing the database fields to be updated.
$keyname
is the primary keyname of the database table.
$updateNulls
is a flag.  If true then object attributes that are null will overwrite the corresponding database fields.  If false then null object attributes are ignored.

Examples

Example: In this example the function newUser is called to create a record in the Joomla users table, then the function updateUser is called to update one of its fields.

// Create new row in users table and return the unique id allocated
// if successful or false otherwise.
function newUser( $name ) {
  global $database;
 
  $user = new stdClass;
  $user->id = NULL;
  $user->name = $name;
 
  if (!$database->insertObject( '#__users', $user, 'id' )) {
    echo $database->stderr();
    return false;
  }
 
  return $user->id;
}
 
// Update an existing user record.
function updateUser( $id, $username ) {
  global $database;
 
  $user = new stdClass;
  $user->id = $id;
  $user->username = $username;
 
  if (!$database->updateObject( '#__users', $user, 'id' )) {
    echo $database->stderr();
    return false;
  }
 
}
 
$id = newUser( 'Linus Torvalds');
updateUser( $id, 'linus' );

Please report any errors on this page to the Developer Documentation Forum.

Last Updated ( Monday, 25 December 2006 )
 
< Prev   Next >