我正在尝试在 Joomla 3.0.3 的简单查询中添加 WHERE 语句。但代码仅在我用 WHERE 语句注释该行时才有效。你有什么建议吗?非常感谢!
<?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 的后端键入此类语句!
最佳答案
自 Joomla! 1.6.x nameQuote
已在 Joomla 中贬值! 3.x 它不再可用。您可以在本文“Potential backward compatibility issues in Joomla 3.0 and Joomla Platform 12.1”中找到更多内容
许多 JDatabase
(又名 JDatabaseDriver
)更改是为了支持 MySQL 以外的数据库。
在 Joomla 中! 3.x 您将需要使用替换 $db->quoteName()
来表示表名或列名,使用 $db->quote
来表示任何值。
因此,您的 where
元素变为:
$query->where($db->quoteName('InstrumentFamily').'='.$db->quote('debt'));
关于php - WHERE 语句在 Joomla 中不起作用! 3.0.3。 PHP请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15670555/