Мне было поручено устранить следующий фрагмент кода, но я не могу понять, что является причиной фатальной ошибки.selectQuery
будет запросом с несколькими результатами (например, select id, metric, text from protocols
), и я пытаюсь проанализировать каждую строку в цикле while ($row = $result->fetch_row()){
, который вызывается в ошибке.У меня есть ощущение, что это связано с store_result
или multi_query
, но я не могу найти ни одного связанного с этим вопроса переполнения стека.Я нашел это в руководстве по PHP, которое, похоже, основано на коде, но ничто в комментариях не помогло.
Ошибка: PHP Fatal error: Call to a member function fetch_row() on a non-object in script.php
Я ценю любую проницательность.
$IS_DEBUG = false ; // Screen output debug flag TODO - this might be a better command-line switch ... someday, maybe ...
$COMMON_WORD_LIST = array(
"a" => 1,"about" => 1,"after" => 1,"all" => 1,"also" => 1,"an" => 1,"and" => 1,"any" => 1,"as" => 1,
"at" => 1,"back" => 1,"be" => 1,"because" => 1,"but" => 1,"by" => 1,"can" => 1,"come" => 1,"could" => 1,
"day" => 1,"do" => 1,"even" => 1,"first" => 1,"for" => 1,"from" => 1,"get" => 1,"give" => 1,"go" => 1,
"good" => 1,"have" => 1,"he" => 1,"her" => 1,"him" => 1,"his" => 1,"how" => 1,"i" => 1,"if" => 1,
"in" => 1,"into" => 1,"it" => 1,"its" => 1,"just" => 1,"know" => 1,"like" => 1,"look" => 1,"make" => 1,
"me" => 1,"most" => 1,"my" => 1,"new" => 1,"no" => 1,"not" => 1,"now" => 1,"of" => 1,"on" => 1,"one" => 1,
"only" => 1,"or" => 1,"other" => 1,"our" => 1,"out" => 1,"over" => 1,"people" => 1,"say" => 1,"see" => 1,
"she" => 1,"so" => 1,"some" => 1,"take" => 1,"than" => 1,"that" => 1,"the" => 1,"their" => 1,"them" => 1,
"then" => 1,"there" => 1,"these" => 1,"they" => 1,"think" => 1,"this" => 1,"time" => 1,"to" => 1,"two" => 1,
"up" => 1,"us" => 1,"use" => 1,"want" => 1,"way" => 1,"we" => 1,"well" => 1,"what" => 1,"when" => 1,
"which" => 1,"who" => 1,"will" => 1,"with" => 1,"work" => 1,"would" => 1,"year" => 1,"you" => 1,"your" => 1,
"td" => 1,"p" => 1,"the" => 1,"valign" => 1,"top" => 1,"width" => 1,"strong" => 1,"tr" => 1,"of" => 1,
"to" => 1,"or" => 1,"a" => 1,"and" => 1,"bottom" => 1,"you" => 1,"is" => 1,"for" => 1,"in" => 1,"nbsp" => 1,
"center" => 1,"align" => 1,"bgcolor" => 1,"yes" => 1,"class" => 1,"no" => 1,"if" => 1,"per" => 1,"sub" => 1,
"be" => 1,"bfbfbf" => 1,"that" => 1,"i" => 1,"not" => 1,"b" => 1,"font" => 1,"on" => 1,"have" => 1,
"vertical" => 1,"u" => 1,"with" => 1,"are" => 1,"colspan" => 1,"at" => 1,"your" => 1,"as" => 1,"e" => 1,
"more" => 1,"this" => 1,"know" => 1,"c" => 1,"don't" => 1,"other" => 1,"reg" => 1,"did" => 1,"how" => 1,
"nowrap" => 1,"than" => 1,"g" => 1,"em" => 1,"li" => 1,"by" => 1,"color" => 1,"table" => 1,"from" => 1,
"d" => 1,"time" => 1,"ff" => 1,"should" => 1,"used" => 1,"it" => 1,"when" => 1,"do" => 1,"has" => 1,
"an" => 1,"one" => 1,"month" => 1,"past" => 1,"was" => 1,"br" => 1,"div" => 1,"ccff" => 1,"jpg" => 1, "s" => 1
);
// function to check for common words
function isCommonWord($word) {
global $COMMON_WORD_LIST;
if (array_key_exists($word,$COMMON_WORD_LIST)) {
return 1;
} else {
return 0;
}
}
function queryField($con, $selectQuery, $field, $indexField){
if ($con->multi_query($selectQuery)) {
do {
/* store first result set */
if ($result = $con->store_result()) {
//if(!is_object($results)){
while ($row = $result->fetch_row()){
/* text that needs to be parsed will be first column of query */
if($indexField=="KEYWORD"){
$protocol_text = strtolower($row[0]);
$protocol_text = preg_replace("/\n/", " ", $protocol_text);
$protocol_text = preg_replace("/\W+\s+/", " ", $protocol_text);
$protocol_text = preg_replace("/\s+\d+\s+/", " ", $protocol_text);
$protocol_text = preg_replace("/\s+\W+/", " ", $protocol_text);
$protocol_text = preg_replace("/\<p\>/", "", $protocol_text);
$protocol_text = preg_replace("/\<\/p\>/", "", $protocol_text);
$protocol_text = preg_replace("/\./", "", $protocol_text);
$protocol_text = preg_replace("/[\/\[\]\{\}_\)\(]+/", " ", $protocol_text);
$protocol_text = trim($protocol_text);
$measure_id=$row[1];
##################################################################################
# ALGORITHM ######################################################################
##################################################################################
# parse words
$textSize=strlen($protocol_text);
echo "TEXT_SIZE||".$textSize.PHP_EOL;
$offset=0;
$match_count=0;
while(preg_match("/([abcdefghijklmnopqrstuvwxyz']+)/", $protocol_text, $matches, PREG_OFFSET_CAPTURE, $offset)) {
... PROPRIETARY ...
if (isCommonWord($matches[0])==0) {
$fullTextInsert = "insert into full_text_indexes (MEASURE_ID, WORD, MATCH_START, MATCH_LENGTH, MATCH_NUMBER, FIELD_INDEXED) values ($measure_id, '$matches[0]', $match_start, $match_length, $match_count, '$indexField')";
$result = sendQuery($con, $fullTextInsert);
if($result) {
echo "SUCCESS||".$fullTextInsert.PHP_EOL;
}else{
die("FAIL||".$fullTextInsert );
}
}
}
}else{
}
}
//}
$result->free();
}
/* print divider */
if ($con->more_results()) {
printf("-----------------\n");
}
} while ($con->next_result());
}
}