问题描述
我正在尝试在Joomla 3.0.3中的简单查询中添加WHERE语句.但是该代码仅在我用WHERE语句注释该行时有效.你有什么建议吗?非常感谢!
I am trying to add a WHERE statement in a simple query in Joomla 3.0.3. but the code only works when I comment the line with the WHERE statement. Do you have any suggestion? Many thanks!
<?php
$query = $db->getQuery(true);
$query->select(array('Name','InstrumentFamily'));
$query->from('instrumenttype');
$query->where($db->nameQuote('InstrumentFamily').'='.$db->quote('debt'));
$db->setQuery($query);
$result = $db->loadAssocList();
print_r($result);
?>
PS:请注意,我正在使用Sourcerer扩展程序在Joomla的后端中键入此类语句!
PS: note that I'm using the Sourcerer extension to type such statements in the back end of Joomla!
推荐答案
自Joomla起!在Joomla中,1.6.x nameQuote
已被贬值! 3.x不再可用.您可以在本文中找到更多信息" Joomla 3.0和Joomla Platform 12.1中潜在的向后兼容性问题 "
Since Joomla! 1.6.x nameQuote
has been depreciated, in Joomla! 3.x it is no longer available. You can find more in this article "Potential backward compatibility issues in Joomla 3.0 and Joomla Platform 12.1"
许多JDatabase
(又名JDatabaseDriver
)更改是为了启用除MySQL以外的更多支持数据库.
A lot of these JDatabase
(aka JDatabaseDriver
) changes are to enable greater support databases other than MySQL.
在Joomla中! 3.x,您将需要在表或列名中使用替换$db->quoteName()
,在任何值中使用$db->quote
.
In Joomla! 3.x you will need to use the replacement $db->quoteName()
for table or column names and $db->quote
for any values.
因此,您的where
元素变为:
$query->where($db->quoteName('InstrumentFamily').'='.$db->quote('debt'));
这篇关于WHERE陈述式在Joomla中无效! 3.0.3. PHP的要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!