Joomla 2.5数据库$ query->其中警告

时间:2012-12-07 13:16:54

标签: joomla joomla2.5

我有这个简单的代码从数据库中选择自定义字符串:

protected function getListQuery()
{

              $db = JFactory::getDBO();
              $query = $db->getQuery(true);

              $query->select('*')
                    ->from('#__person');

              $name = 'tom';

              $query->where('name LIKE %'.$db->quote($name).'%');

              return $query;
} 

不幸的是它给了我一个错误:

  

警告:mysql_num_rows()要求参数1为resource,boolean   在xxx \ public \ libraries \ joomla \ database \ database \ mysql.php中给出   第293行

如果我移除其中,则一切正常。我可以调试数据查询吗?我想看看最终查询到MySQL服务器的最新情况。

我们将不胜感激。

1 个答案:

答案 0 :(得分:1)

我成功地为我工作了:

protected function getListQuery()
{

    $db = JFactory::getDBO();
    $query = $db->getQuery(true);

    $query->select('*')
          ->from('#__person');

    $name = 'tom';

    $name = $db->Quote('%'.$db->escape($name, true).'%');
    $query->where($db->nameQuote('name').' LIKE '.$name);


    //debug the query  
    // echo nl2br(str_replace('#__','prefix_',$query)); die;

    return $query;

}