update record in database using jdatabase

你离开我真会死。 提交于 2019-12-10 20:55:20

问题


How do to use jdatabase to update a record in Joomla3. Here is what i have so far.

$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$query->update('#__test AS h');
$query->set('h.name = 'apple', h.description= 'orange', h.url = 'bannana'');
$query->where('h.id=1');    
$db->setQuery($query);

Am i missing something simple?


回答1:


I just spent the day banging my head against the wall with this too. You're very close, but you just need some minor tweaks.

$query->set('h.name = 'apple', h.description= 'orange', h.url = 'bannana'');

should be (note the quotes):

$query->set('h.name = "apple", h.description= "orange", h.url = "bannana"');

Also:

$db =& JFactory::getDBO();

will throw a "Strict Standards" warning in developer mode. Just remove the ampersand.

The missing piece:

try {
    $result = $db->execute();
} catch (Exception $e) {
    die($e->getMessage());
}

P.S. I realize this answer is a bit late so I hope that you've solved your problem by now. I am posting this answer for those who come across it later and can't find the solution in Joomla's shitty documentation.



来源:https://stackoverflow.com/questions/14531603/update-record-in-database-using-jdatabase

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!