Добрый день, нужна помощь, при открытии раздела на портале, вылазит пустая страница. Зашёл в логи ошибок, там вот такое добро: Uncaught Error: Call to a member function fetch_assoc() on bool in C:\\ProgramData\\STU-Soft\\www\\GARAGE_food_coffee\\include\\db\\mysqlroutines.common.inc:2161\nStack trace:\n#0 Вот 2161 строчка кода: function db_isReportNotExpire($cn, $oguid, $rguid, $idlanguage, $skbranch = NULL) { $ido = db_getIDObjectByGuid($cn, $oguid, $skbranch); $idr = db_getIDReportByGuid($cn, $rguid, $idlanguage, $skbranch); db_setTimeZone($cn); $query = "SELECT 1 FROM `reportindex` WHERE idobject = ".$ido." AND idreport = ".$idr." AND (from_unixtime(ri_expirationdate_tmst) > NOW() or ri_expirationdate_tmst is null) AND skbranch = ".($skbranch == NULL ? "(SELECT `skbranch` FROM `branches` WHERE ismain = 1 LIMIT 1)": $skbranch)." LIMIT 1;"; $ar = $cn->query($query)->fetch_assoc(); // 2161 строчка кода logError($cn, $query); return (is_array($ar) && sizeof($ar) > 0); }
Я совсем не разбираюсь в этом, поэтому и спросил здесь, чтобы мне прям тыкнули пальцем, что именно нужно изменить)
возвращает false вместо объекта, у которого есть метод fetch_assoc(). Посмотрите, какой сформировали запрос в $query
Во фрилансе по наему специалиста, а не тогда, когда работник Кафе пытается выпендриться перед начальством, при этом сам ни*уя не знает куда и зачем лезет. Приходит во форумы и с кислой моськой выкладывает кусок говнокода, указывает на причину и при этом сам палец об палец ничего для решения не сделал. Лови отзыв о себе.
Я просил помощь, а не комментарии о том что я ничего не знаю от рандомного типа. Если не можешь или не хочешь помочь не нужно выписывать, будь добрее чел...
Преобразуйте часть кода, например, таким образом: PHP: try { $ar = $cn->query($query)->fetch_assoc(); // 2161 строчка кода } catch (\Throwable $ex) { logError($cn, $query); exit; // прервать выполнение (Fatal error отлаживаем) } И ищите там, куда лог пишется
Ошибка в строке запроса: PHP: $query = "SELECT 1 FROM `reportindex` WHERE idobject = ".$ido." AND idreport = ".$idr." AND (from_unixtime(ri_expirationdate_tmst) > NOW() or ri_expirationdate_tmst is null) AND skbranch = ".($skbranch == NULL ? "(SELECT `skbranch` FROM `branches` WHERE ismain = 1 LIMIT 1)": $skbranch)." LIMIT 1;"; Какая ошибка, зависит от того, что запрашиваем. Ведь я не знаю что ищем.
Это индексация отчетов, вот код: PHP: // дата создания отчета ( индексации ) function db_getReportCreationDate($cn, $oguid, $rguid, $idlanguage, $skbranch = NULL){ $ido = db_getIDObjectByGuid($cn, $oguid, $skbranch); $idr = db_getIDReportByGuid($cn, $rguid, $idlanguage, $skbranch); db_setTimeZone($cn); $query = "SELECT DATE_FORMAT(from_unixtime(ri_creationdate_tmst),'%d.%m.%Y %H:%i') AS ri_creationdate FROM `reportindex` WHERE skbranch = ".$skbranch." and idobject = ".$ido." and idreport = ".$idr." LIMIT 1;"; $ar = $cn->query($query)->fetch_assoc(); logError($cn, $query); if (is_array($ar) && sizeof($ar) > 0){ return $ar['ri_creationdate']; } else { return ''; } } function db_getReportIndexBody($cn, $oguid, $rguid, $idlanguage, $skbranch = NULL){ $ido = db_getIDObjectByGuid($cn, $oguid, $skbranch); $idr = db_getIDReportByGuid($cn, $rguid, $idlanguage, $skbranch); $query = "SELECT `body` as body FROM `reportindex` WHERE idobject = ".$ido." and idreport = ".$idr." LIMIT 1;"; $ar = $cn->query($query)->fetch_assoc(); logError($cn, $query); if (is_array($ar) && sizeof($ar) > 0){ return $ar['body']; } else { return ''; } } function db_isReportNotExpire($cn, $oguid, $rguid, $idlanguage, $skbranch = NULL) { $ido = db_getIDObjectByGuid($cn, $oguid, $skbranch); $idr = db_getIDReportByGuid($cn, $rguid, $idlanguage, $skbranch); db_setTimeZone($cn); $query = "SELECT 1 FROM `reportindex` WHERE idobject = ".$ido." AND idreport = ".$idr." AND (ri_expirationdate_tmst is not null) AND (from_unixtime(ri_expirationdate_tmst) > NOW() or ri_expirationdate_tmst is null) AND skbranch = ".($skbranch == NULL ? "(SELECT `skbranch` FROM `branches` WHERE ismain = 1 LIMIT 1)": $skbranch)." LIMIT 1;"; $ar = $cn->query($query)->fetch_assoc(); logError($cn, $query); return (is_array($ar) && sizeof($ar) > 0); } function db_isReportHaveExpireDate($cn, $oguid, $rguid, $idlanguage, $skbranch = NULL) { $ido = db_getIDObjectByGuid($cn, $oguid, $skbranch); $idr = db_getIDReportByGuid($cn, $rguid, $idlanguage, $skbranch); $query = "SELECT 1 FROM `reportindex` WHERE idobject = ".$ido." AND idreport = ".$idr." AND (ri_expirationdate_tmst is not null) AND skbranch = ".($skbranch == NULL ? "(SELECT `skbranch` FROM `branches` WHERE ismain = 1 LIMIT 1)": $skbranch)." LIMIT 1;"; $ar = $cn->query($query)->fetch_assoc(); logError($cn, $query); return (is_array($ar) && sizeof($ar) > 0); } function db_ReportResetExpireDate($cn, $oguid, $rguid, $idlanguage, $skbranch = NULL) { $ido = db_getIDObjectByGuid($cn, $oguid, $skbranch); $idr = db_getIDReportByGuid($cn, $rguid, $idlanguage, $skbranch); $query = 'SET @@session.time_zone = "+00:00";'; $result = $cn->query($query); logError($cn, $query); $query = "UPDATE `reportindex` SET ri_expirationdate_tmst = UNIX_TIMESTAMP(NOW()) WHERE idobject = ".$ido." AND idreport = ".$idr." AND skbranch = ".($skbranch == NULL ? "(SELECT `skbranch` FROM `branches` WHERE ismain = 1 LIMIT 1)": $skbranch).";"; $result = $cn->query($query); logError($cn, $query); } function db_getReportIDLanguage($cn, $oguid, $rguid, $idlanguage, $skbranch = NULL) { $ido = db_getIDObjectByGuid($cn, $oguid, $skbranch); $idr = db_getIDReportByGuid($cn, $rguid, $idlanguage, $skbranch); $query = "SELECT `idlanguage` FROM `objectsreports` WHERE idobject = ".$ido." AND idreport = ".$idr." AND skbranch = ".($skbranch == NULL ? "(SELECT `skbranch` FROM `branches` WHERE ismain = 1 LIMIT 1)": $skbranch).";"; $ar = db_runQueryAndReturnArray($cn, $query); if (is_array($ar) && sizeof($ar) > 0){ return $ar[0]['idlanguage']; } else { return $idlanguage; } } function db_isObjectsReportsExits($cn, $oguid, $rguid, $idlanguage, $skbranch = NULL) { $ido = db_getIDObjectByGuid($cn, $oguid, $skbranch); $idr = db_getIDReportByGuid($cn, $rguid, $idlanguage, $skbranch); $query = "SELECT 1 FROM objectsreports WHERE idobject = ".$ido." AND idreport = ".$idr." AND skbranch = ".($skbranch == NULL ? "(SELECT `skbranch` FROM `branches` WHERE ismain = 1 LIMIT 1)": $skbranch)." LIMIT 1;"; $ar = $cn->query($query)->fetch_assoc(); logError($cn, $query); return (is_array($ar) && sizeof($ar) > 0); } function db_isObjectExits($cn, $oguid, $skbranch = NULL) { $query = "SELECT 1 FROM objects WHERE o_guid = '".$oguid."' AND skbranch = ".($skbranch == NULL ? "(SELECT `skbranch` FROM `branches` WHERE ismain = 1 LIMIT 1)": $skbranch)." LIMIT 1;"; $ar = $cn->query($query)->fetch_assoc(); logError($cn, $query); return (is_array($ar) && sizeof($ar) > 0); } function db_isObjectsMultianguage($cn, $oguid, $rguid, $skbranch = NULL) { $ido = db_getIDObjectByGuid($cn, $oguid, $skbranch); $idr = db_getIDReportByGuid($cn, $rguid, 0, $skbranch); $query = "SELECT 1 FROM objectsreports WHERE idobject = ".$ido." AND idreport = ".$idr." AND (idlanguage IS NULL or idlanguage = 0) AND skbranch = ".($skbranch == NULL ? "(SELECT `skbranch` FROM `branches` WHERE ismain = 1 LIMIT 1)": $skbranch)." LIMIT 1;"; $ar = $cn->query($query)->fetch_assoc(); logError($cn, $query); return (is_array($ar) && sizeof($ar) > 0); } function db_getUserRightsToReport($cn, $user_ids, $rguid, $oguid, $idlanguageContent, $skbranch = NULL) { if (null === $user_ids || $user_ids[0] == 0 ) return true; $ids = implode(",", $user_ids); $deflangid = db_getDefaultLangID($cn); $addSelectWithDefaultLang = "".($deflangid != null && $deflangid <> $idlanguageContent ? "OR rep.idlanguage = ".$deflangid." " : ""); //9791 Сначала запретим те отчеты, на которые стоит явный запрет $query = "SELECT DISTINCT 1 FROM rightsreports as rr INNER JOIN reports as rep ON rr.idreport = rep.idreport AND rr.skbranch = rep.skbranch WHERE rr.iduser in (".$ids.") AND rep.skbranch = ".($skbranch == NULL ? "(SELECT `skbranch` FROM `branches` WHERE ismain = 1 LIMIT 1)": $skbranch)." AND rep.r_guid='".mysqli_real_escape_string($cn,$rguid)."' AND (rep.idlanguage = ".$idlanguageContent." OR rep.idlanguage IS NULL OR rep.idlanguage = 0 ".$addSelectWithDefaultLang.") AND `deny_allow` = 0;"; $ar = $cn->query($query)->fetch_assoc(); logError($cn, $query); if (is_array($ar) && sizeof($ar) > 0) return null; //9791 Теперь разрешим доступ к отчету, если объект отчета - наше физлицо. if ($oguid != ""){ $query = "SELECT DISTINCT 1 FROM users as u WHERE u.iduser in (".$ids.") and u.user_guid='".mysqli_real_escape_string($cn,$oguid)."';"; $ar = $cn->query($query)->fetch_assoc(); logError($cn, $query); if (is_array($ar) && sizeof($ar) > 0) return true; }
Очевидно ведь, что для констатации факта наличия --- Добавлено --- @Anton23_23, return забыли оставить вне (после) блока try - catch. --- Добавлено --- @Anton23_23, а искать результат (текст сформированного запроса) надо там, куда его функция logError пишет.
Дабы не плодить темы, напишу здесь. Проблема абсолютно аналогичная. Код (Text): Call to a member function fetch_assoc() on boolean in /www/feeds/classes/ImportXmlDB.php: Stack trace: #0 /www/feeds/getXml.php(24): ImportXmlDB->getItemsFromDB() #1 {main} thrown in /www/feeds/classes/ImportXmlDB.php on line PHP: $respArr = array(); for($i = 3; $i < 17; $i++){ if(!$this->selectedCategories || in_array($i, $this->selectedCategories)){ $paramJoins = $this->getParamJoins($i); /* Запрос для объектов */ $queryString = 'SELECT o.id, o.name, o.text2, addr.value as addr, square.value as square, city.value as city, region.value as region, price.value as price, street.value as street, house.value as house, r1.id as category_id, '.$paramJoins['select'].' r1.parent_id, GROUP_CONCAT(i.`big` ORDER BY i.ord ) AS photos FROM realty_objects o LEFT JOIN realty r ON r.id=o.parent_id LEFT JOIN realty r1 ON r1.id=r.parent_id LEFT JOIN images i ON (i.record_id=o.id AND i.model IS NOT NULL) LEFT JOIN param_values price ON (price.record_id = o.id AND price.param_id='.($i < 10 ? 24 : 40).') '.$paramJoins['joins'].' WHERE o.`on`= 1 AND o.lng_id=1 AND r1.id = '.$i.' '.($this->excludeIdsString ? $this->excludeIdsString : '').' GROUP BY o.id'; /* Запрос для проектов */ $queryStringProjects = 'SELECT o.id, o.name, o.text2, addr.value as addr, square.value as square, city.value as city, region.value as region, price.value as price, street.value as street, house.value as house, r2.id as category_id, '.$paramJoins['select']. ' r2.parent_id, GROUP_CONCAT(i.`big` ORDER BY i.ord ) AS photos FROM realty o LEFT JOIN realty r2 ON r2.id=o.parent_id LEFT JOIN images i ON (i.record_id=o.id AND i.model IS NOT NULL) LEFT JOIN param_values price ON (price.record_id = o.id AND price.param_id='.($i < 10 ? 24 : 40).') '.$paramJoins['joins'].' WHERE o.`on`= 1 AND o.lng_id=1 AND r2.id = '.$i. ' '.($this->excludeIdsString ? $this->excludeIdsString : ''). ' GROUP BY o.id'; $resp = $this->query->query($queryString); $respProjects = $this->query->query($queryStringProjects); /********ниже строка с ошибкой *********/ while($item = $resp->fetch_assoc()){ if(!$this->selectedIds || in_array($item['id'], $this->selectedIds)){ $respArr[] = $item; } } while($item = $respProjects->fetch_assoc()){ if(!$this->selectedIds || in_array($item['id'], $this->selectedIds)){ $respArr[] = $item; } } } } return $respArr; } Буду признателен за наводку!
Ну так напечатай готовый запрос, который отправляешь. Тем более он у тебя даже не подготовленный Adminer, HeidySQL, сам PHP Storm, да куча ещё
Собрал готовый запрос, подправил ошибки, PHP: public function getItemsFromDB(){ $respArr = array(); for($i = 3; $i < 17; $i++){ if(!$this->selectedCategories || in_array($i, $this->selectedCategories)){ $paramJoins = $this->getParamJoins($i); $queryString = 'SET SQL_BIG_SELECTS=1; SELECT o.id, o.name, o.text2, addr.value as addr, square.value as square, city.value as city, region.value as region, price.value as price, street.value as street, house.value as house, r1.id as category_id, '.$paramJoins['select'].' r1.parent_id, GROUP_CONCAT(i.`big` ORDER BY i.ord ) AS photos FROM realty_objects o LEFT JOIN realty r ON r.id=o.parent_id LEFT JOIN realty r1 ON r1.id=r.parent_id LEFT JOIN images i ON (i.record_id=o.id AND i.model IS NOT NULL) LEFT JOIN param_values price ON (price.record_id = o.id AND price.param_id='.($i < 10 ? 24 : 40).') '.$paramJoins['joins'].' WHERE o.`on`= 1 AND o.lng_id=1 AND r1.id = '.$i.' '.($this->excludeIdsString ? $this->excludeIdsString : '').' GROUP BY o.id'; $queryStringProjects = 'SET SQL_BIG_SELECTS=1; SELECT o.id, o.name, o.text2, addr.value as addr, square.value as square, city.value as city, region.value as region, price.value as price, street.value as street, house.value as house, r2.id as category_id, '.$paramJoins['select'].' r2.parent_id, GROUP_CONCAT(i.`big` ORDER BY i.ord ) AS photos FROM realty o LEFT JOIN realty r2 ON r2.id=o.parent_id LEFT JOIN images i ON (i.record_id=o.id AND i.model IS NOT NULL) LEFT JOIN param_values price ON (price.record_id = o.id AND price.param_id='.($i < 10 ? 24 : 40).') '.$paramJoins['joins'].' WHERE o.`on`= 1 AND o.lng_id=1 AND r2.id = '.$i.' '.($this->excludeIdsString ? $this->excludeIdsString : '').' GROUP BY o.id'; $resp = $this->query->query($queryString); $respProjects = $this->query->query($queryStringProjects); while($item = $resp->fetch_assoc()){ if(!$this->selectedIds || in_array($item['id'], $this->selectedIds)){ $respArr[] = $item; } } while($item = $respProjects->fetch_assoc()){ if(!$this->selectedIds || in_array($item['id'], $this->selectedIds)){ $respArr[] = $item; } } } } return $respArr; } в phpmyadmin отработал. Все равно вываливается Код (Text): Call to a member function query() on a non-object in /www/feeds/classes/ImportXmlDB.php on line 61 61 строка PHP: $resp = $this->query->query($queryString);