WHERE statement not working in Joomla! 3.0.3. php request

江枫思渺然 提交于 2019-12-24 01:59:10

问题


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: note that I'm using the Sourcerer extension to type such statements in the back end of Joomla!


回答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"

A lot of these JDatabase (aka JDatabaseDriver) changes are to enable greater support databases other than MySQL.

In Joomla! 3.x you will need to use the replacement $db->quoteName() for table or column names and $db->quote for any values.

So, your where element becomes:

$query->where($db->quoteName('InstrumentFamily').'='.$db->quote('debt'));


来源:https://stackoverflow.com/questions/15670555/where-statement-not-working-in-joomla-3-0-3-php-request

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