如何执行自定义MySQL查询以从Zoo数据库表中获取记录?
此查询的内容:
SELECT "64ccc68f-4af3-4c02-8c0f-8ec5977bacb2"
FROM #__zoo_item
WHERE application_id=1 and state=1 and type='handy'
答案 0 :(得分:0)
阅读Documentaion,
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// Select all records from the user profile table where key begins with "custom.".
// Order it by the ordering field.
$query->select($db->quoteName(array('user_id', 'profile_key', 'profile_value', 'ordering')));
$query->from($db->quoteName('#__user_profiles'));
$query->where($db->quoteName('profile_key') . ' LIKE '. $db->quote('\'custom.%\''));
$query->order('ordering ASC');
// Reset the query using our newly populated query object.
$db->setQuery($query);
// Load the results as a list of stdClass objects (see later for more options on retrieving data).
$results = $db->loadObjectList();
答案 1 :(得分:0)
根据您在问题中发布的查询,以下是Joomla等效项:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName(array('64ccc68f-4af3-4c02-8c0f-8ec5977bacb2')))
->from($db->quoteName('#__zoo_item'))
->where($db->quoteName('application_id') . ' = 1 AND '.
$db->quoteName('state') . ' = 1 AND '.
$db->quoteName('type') . ' = ' $db->quoteName('handy'));
$db->setQuery($query);
$results = $db->loadObjectList();
$results
是您查询结果的对象,然后您可以随意执行任何操作。
希望这有帮助
答案 2 :(得分:0)
您可以使用zoo API轻松获得所需内容。我必须说他们有最好的API来获取API。使用项目获取动物园记录的所有信息,你只需要将动物园项目ID传递给函数。
$app = App::getInstance('zoo');
$item = $app->table->item->get($ITEM_ID); // Zoo Record Id
$Element_Id = "64ccc68f-4af3-4c02-8c0f-8ec5977bacb2"; // One of the text field element id
$element_value = $item->getElement($Element_Id)->getElementData()->get('value');
// $element_value contains the actual value of element id $Element_Id of item id $ITEM_ID.
阅读此博客以了解更多信息。 http://atpatil.blogspot.in/2013/04/access-zoo-element-data-anywhere-in.html