PHP警告:mysqli_num_rows()期望参数1为mysqli_result,给定布尔值 - 更改数据库密码后出错

时间:2015-03-13 21:42:26

标签: php warnings

首先,我没有PHP程序员,我们本周失去了我们的开发,但我了解它的工作原理.. :(我们在php中有这个错误,与我们在主要显示的新产品有关页。

PHP警告:

  

mysqli_num_rows()期望参数1为mysqli_result,在....中给出布尔值。

此错误是对这行代码的影响;

if (mysqli_num_rows($result)) {

,代码是;

$result = mysqli_query($mysql,"SELECT products.id,products.strKey,products.strModel,IFNULL(products.strBand,companies.strName) AS strBrand,products.intPoints,products_images.strPath AS strImagePath,MIN(products_sizes.dblPriceRegular) AS dblPriceRegular,MIN(LEAST(products_sizes.dblPriceSpecial,IFNULL(products_sizes.dblPricePromotion,products_sizes.dblPriceSpecial))) AS dblPriceSpecial,MIN(products_sizes.dblPrice) AS dblPrice,sections.strKey"._LANG_." AS strKeySection,categories.strKey"._LANG_." AS strKeyCategory,categories.strName"._LANG_." AS strCategory,categories_sub.strKey"._LANG_." AS strKeySubCategory,categories_sub.strName"._LANG_." AS strSubCategory FROM products_new JOIN products ON products.id = products_new.id JOIN products_categories ON products_categories.intProduct = products.id JOIN products_sizes ON products_sizes.intProduct = products.id JOIN categories ON categories.id = products_categories.intCategory JOIN sections ON sections.id = categories.intSection LEFT JOIN companies ON companies.id = products.intCompany LEFT JOIN categories_sub ON categories_sub.id = products_categories.intSubCategory LEFT JOIN products_images ON products_images.intProduct = products.id AND products_images.intType = 2 AND products_images.intOrder = 1 GROUP BY products.id ORDER BY ".(_USER_LAST_VISIT_ ? "IF(products.dtimeUpdated>FROM_UNIXTIME("._USER_LAST_VISIT_."),0,1)," : "")."RAND() LIMIT "._HOME_NEWPRODUCTS_);
if (mysqli_num_rows($result)) {
    echo "              <h2 class=\"new-products\">".translate("HOME.NEWPRODUCTS")."</h2>\n";
    echo "              <ul class=\"liste_produit\">\n";
    $intCol = 0;
    $intRow = 0;
    while ($row = mysqli_fetch_assoc($result)) {
        $intCol++;
        if ($intCol > 3) $intCol = 1;
        switch ($intCol) {
            case 1:
                $intRow++;
                $strClass = "first";
                if ($intRow > 1) {
                    echo "              <!--[if IE 6]>\n";
                    echo "              </ul>\n";
                    echo "              <ul class=\"liste_produit liste_produit_ie6\">\n";
                    echo "              <![endif]-->\n";
                }
                break;
            case 2:
                $strClass = "second";
                break;
            case 3:
                $strClass = "third";
                break;
        }
        $strLink = "../".$row["strKeySection"]."/".$row["strKeyCategory"]."/".(!empty($row["strKeySubCategory"]) ? $row["strKeySubCategory"]."/" : NULL).$row["strKey"]."/";
        echo "                  <li class=\"".$strClass."\">\n";
        echo "                      <a href=\"".$strLink."\" class=\"\"><img src=\"/files/products/".$row["strImagePath"]."\" alt=\""._htmlentities(!empty($row["strModel"]) ? $row["strModel"] : translate("PRODUCT.NONAME"))."\" /><span>".translate("PRODUCT.NEW")."</span></a>\n";
        echo "                      <div class=\"infos\">\n";
        echo "                          <div class=\"head\"><a href=\"".$strLink."\">".(!empty($row["strBrand"]) ? $row["strBrand"] : translate("PRODUCT.NONAME"))."</a></div>\n";
        echo "                          <div class=\"body\">\n";
        echo "                              <h6>".(!empty($row["strModel"]) ? $row["strModel"] : translate("PRODUCT.NONAME"))."</h6>\n";
        echo "                              <p class=\"description\">".$row["strCategory"].(!empty($row["strSubCategory"]) ? " - ".$row["strSubCategory"] : NULL)."</p>\n";
        if ($row["dblPrice"] > 0) echo "                                <p class=\"prix\">".translate("PRODUCT.PRICE").":&nbsp;".($row["dblPriceSpecial"] < $row["dblPriceRegular"] ? "<span class=\"strike\">".currencyDisplay($row["dblPriceRegular"],1)."</span> ".currencyDisplay($row["dblPriceSpecial"],1) : currencyDisplay($row["dblPriceRegular"],1))."</p>\n";
        if ($row["intPoints"] > 0) echo "                               <p class=\"prix\">".translate("EXOPOINTS").":&nbsp;".$row["intPoints"]."</p>\n";
        echo "                          </div>\n";
        echo "                          <div class=\"footer\"></div>\n";
        echo "                      </div>\n";
        echo "                      <div class=\"clearBoth\"></div>\n";
        echo "                  </li>\n";
    }
    echo "              </ul>\n";
    echo "              <div class=\"clearBoth\"></div>\n";
    echo "              <div class=\"ombre new_products\"><a href=\"".translate("SECTIONS.NEW.PATH")."?o=new\" class=\"btn\">".translate("HOME.NEWPRODUCTS")."</a></div>\n";
    echo "              <div class=\"clearBoth\"></div>\n";
}

我知道最近代码中没有任何变化。更改的是DB密码和一些已关闭的密码(SSL 2.0,SSL 3.0)...

所有网站都在运行,但主页上的新产品部分中没有显示任何内容。

有什么想法吗?

编辑:错误是SQL视图使用了MySQL中另一个被删除的用户。视图已更改为使用该数据库的特定用户。一切都恢复正常了!

全部谢谢!

2 个答案:

答案 0 :(得分:0)

也许你的$result错了。检查你的SQL查询并尝试var_dump($result);并向我显示输出。

另外,检查$mysql

var_dump($mysql);

答案 1 :(得分:0)

你得到这个错误的唯一原因是mysqli_query返回一个布尔值,如果查询失败,它只会对select做。

我建议直接针对数据库运行此查询,并打印出mysqli_error