From Joomla! Documentation

Revision as of 07:18, 22 September 2009 by Nev3rm0re (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


updateObject($tableName, $object, $key, $updateNulls = true)

If you don't want to write your own SQL and bother with escaping you can use this method and JDatabaseMySQL will do it automatically for you.


First parameter is a string with the name of table you are going to update

Second parameter supposed to be object, but you can easily convert associative array into object using typecasting.

Third parameter tell updateObject what property(array key) to use as a primary key.


 $user = (object) array(
   'id' => 1,
   'username' => 'user',
   'firstname' => 'Default',
   'lastname' => 'User',
 $db = JFactory::getDBO();
 $db->updateObject('my_user_table', $user, 'id');

Every value is automatically quoted using Quote() method.