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 5 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->insertObject

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

Last reviewed: Not reviewed
phpDocumentor

database->insertObject

Inserts a new database table row using data from an object.  Returns true if the insertion was successful; false otherwise.

Syntax

boolean insertObject ( string $table, object &$object [, string $keyname [, boolean $verbose ]] )

$table
is the name of the database table.
$object
is an object containing the database fields to be inserted.  Attributes that are arrays or objects, have a null value or have a name beginning with an underscore, are ignored when setting the database fields.
$keyname
is the primary keyname of the database table. If this is not null then the $keyname attribute of $object will be updated with the unique id number returned by the database insertion. This parameter is optional and if omitted defaults to null.
$verbose
is a flag. If true then the SQL query and the unique id returned by the query are output. If false then no output is produced. This parameter is optional and if omitted defaults to false.

Examples

Example: This example inserts a new row in the Joomla users table.  Notice that the 'id' field is set to null before calling insertObject and will be updated with the unique id number allocated by the database.

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

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

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