WHERE statement not working in Joomla! 3.0.3. php

2019-07-09 20:49发布

问题:

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'));


标签: php mysql joomla