Error: class.product.php calling method on boolean

  • Hi,


    I'm using the HHG-Multistore CE, version 4.10.2 (latest available).


    Internally, the ADO method SelectLimit is used, and then a RecordCount method is called to see how many were selected. However, if no records were selected (the query 'failed'), it will return false (instead of the result). This will result in the page not being able to render correctly (because it'll crash).


    Therefore, in `core/classes/class.product.php:600`, I had to change

    PHP: core/classes/class.product.php
    1. if ($best_sellers->RecordCount() >= MIN_DISPLAY_BESTSELLERS) {


    into


    PHP: core/classes/class.product.php
    1. if ($best_sellers && $best_sellers->RecordCount() >= MIN_DISPLAY_BESTSELLERS) {
  • Hi,


    PHP: core/vendor/adodb/adodb.inc.php
    1. /**
    2. * synonyms RecordCount and RowCount
    3. *
    4. * @return the number of rows or -1 if this is not supported
    5. */
    6. function RecordCount() {
    7. return $this->_numOfRows;
    8. }

    RecordCount returns an integer if there are no results:


    Quote

    core/classes/class.product.php:797:int 0

    If you get an error, it's caused by an SQL error and not due missing records.



    P.S.: Du kannst auch gerne auf Deutsch schreiben ;)

  • The method RecordCount exists only for classes of type ADORecordSet. The SelectLimit method does not always return such a set, according to this page.


    When it's caused by an SQL error (or missing tables, which could also be the cause of SQL errors), then that'd be a bug as well - since I'm using the default installation, and everything *should* work 'out of the box'. :D

  • It's an ADORecordSet until the query is buggy. We couldn't reproduce your case, so it would be better to get your Query. Do following change and post your built query:


    PHP: core/classes/class.product.php
    1. $best_sellers = $this->registry['db']->query_limit($best_sellers_query, MAX_DISPLAY_BESTSELLERS, -1, true);

    change to:


    PHP: core/classes/class.product.php
    1. debug($best_sellers_query);
    2. $best_sellers = $this->registry['db']->query_limit($best_sellers_query, MAX_DISPLAY_BESTSELLERS, -1, true);

    reproduce your error and post shown query. Revert changes after then.

  • To be precise, $best_sellers becomes false instead of ADORecordSet



    Code
    1. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'p.products_ordered > 0 AND (o2s.store_1 = 1 OR o2s.store_all = 1) AND p.product' at line 1
  • Ok, seams to be an older MySQL Version or Strict mode is activated.
    Change


    to

  • MySQL version 5.7.17
    Strict-mode ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION


    (The strict level was the default for my MySQL installation.)


    Changing the parenthesis like you suggested unfortunately had no effect.

  • Could you try this query, please

  • Okay, the Error 1064 (42000) was caused by a whitespace I removed - oops.


    The actual error being:


    Code
    1. ERROR 3065 (HY000): Expression #1 of ORDER BY clause is not in SELECT list, references column 'hhg.p.products_ordered' which is not in SELECT list; this is incompatible with DISTINCT
  • You should restore the origin file and if you have the error again, you could add the column to the select list.