问题描述
如何使用jdatabase更新Joomla3中的记录.这是我到目前为止所拥有的.
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?
推荐答案
我也花了整整一天的时间把头撞在墙上.您的位置非常接近,但是您只需要进行一些细微的调整即可.
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'');
应为(请注意引号):
$query->set('h.name = "apple", h.description= "orange", h.url = "bannana"');
也:
$db =& JFactory::getDBO();
将在开发人员模式下引发严格标准"警告.只需取下&"号即可.
will throw a "Strict Standards" warning in developer mode. Just remove the ampersand.
遗失的部分:
try {
$result = $db->execute();
} catch (Exception $e) {
die($e->getMessage());
}
P.S.我知道这个答案有点晚了,所以希望您现在已经解决了您的问题.我将这个答案发布给以后遇到它的人,但在Joomla的拙劣文档中找不到解决方案.
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.
这篇关于使用jdatabase更新数据库中的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!