mysql query resulting in numerous output makes php page go blank
I use like query forsearch function. All goes well when I search for keywords that are few in db. However when the keyword is "popular" in db, the screen goes blank page.
function dbSearch($q) //$q is array of keywords
{
global $mainframe, $option;
$db =& JFactory::getDBO();
$str = implode("%' AND text LIKE '%", $q);
$str = str_replace("AND text LIKE '%-", "AND text NOT LIKE '%", $str);
$lim = $mainframe->getUserStateFromRequest("$option.limit", 'limit', 100, 'int');
$lim0 = JRequest::getVar('limitstart', 0, '', 'int');
$query = "SELECT SQL_CALC_FOUND_ROWS * FROM `table` WHERE type=4 AND text LIKE '%".$str."%' ORDER BY ref ASC";
$db->setQuery( $query );
$rows = $db->loadObjectList();
$count = count($rows);
if ($db->getErrorNum())
{
echo $db->stderr();
开发者_运维技巧 return false;
}
$db->setQuery('SELECT FOUND_ROWS();');
jimport('joomla.html.pagination');
$pageNav = new JPagination( $db->loadResult(), $lim0, $lim );
HTML_output::showFoundResults($rows, $pageNav, $count);
}
Is something wrong in the query above? why it fails on numerous results?
My guess is that your PHP is taking to long to generate the results based on the query. Your apache error log is likely going to show a PHP timout error as the page too longer than 30 seconds to generate the page.
Try setting the LIMIT to something much smaller like 10 and see if it is able to generate a page.
Another thing you can do is skip 'stopwords' as they are called, words like 'and', 'the', etc. that are very common in a language. Search engines do this, and a quick search will give you more details and lists of stopwords.
You can see how long the query takes to execute by running the query in a tool like phpMyAdmin.
SELECT SQL_CALC_FOUND_ROWS * FROM `table` WHERE type=4 AND text LIKE '%jabberwocky%' ORDER BY ref ASC";
Compared to
SELECT SQL_CALC_FOUND_ROWS * FROM `table` WHERE type=4 AND text LIKE '%the%' ORDER BY ref ASC";
In the same query tool, if you put 'EXPLAIN ' in front of the query, MySQL will return a list of all the actions it had to do to complete the query.
One thing to note, is that a search for the word 'the' will also return results for 'theory' the way your query is constructed. Not an easy thing to code around without going to a REGEX query.
Blank page comes after how many time ? What is the value of max_execution_time directive in php configuration file ?
If it's the same time try to increase this value, or make some improvement on query or table.
Blank pages are normally indicative of a fatal error, or possibly a parse error. If you have set error logging to maximum and its still showing a blank page, then try adding [code] php_value display_errors 1 php_value display_startup_errors 1 [/code]
to your .htaccess file
精彩评论