Method 1
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;
Method 2
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->insert($db->nameQuote('#__users'));
$query->set($db->nameQuote('name').'='.$db->quote($$name).','.
$db->nameQuote('username').'='.$db->quote($username));
$db->setQuery( $query );
$db->query();
$new_id = $db->insertId();
I'm using Joomla and use both above queries which lets me the get the work done. My problem is what is the difference between method 1 and method 2? What's the industry standard? Are there any specific situation I should use above methods? Which one is better and why?
Thanks