Inserting a Record in Joomla Using JDatabase::insertObject()


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. //Create row object
  2. $db = JFactory::getDBO();
  3. $row = new JObject();
  4. $row->created_by = (int)$user->id;
  5. $row->title = 'My Favorites';
  6. $row->alias = JFilterOutput::stringUrlSafe($row->title); //format in slashed alias format
  7. $row->default = 1;
  8.  
  9. //third parameter is key field
  10. $ret = $db->insertObject('#__jxgallery_lightboxes', $row, 'lightbox_id');
  11.  
  12. if (!$ret) {
  13. $this->setError($db->getErrorMsg());
  14. return false;
  15. }
  16.  
  17. //Get the new record id
  18. $lightbox = (int)$db->insertid();

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.