There are several common problems in osCommerce with join syntax when upgrading MySQL from 4.1 to 5.0.x. The exact fix for each join problem depends of the version of oscommerce being used and the patches or contributions that have been applied. The general problem is that the comma operator precedence has changed so that list syntax joins can’t be mixed with explicit joins in the same way. Where this worked previously:
|
|
select t1.id , t2.some_column from some_table as t1, another_table as t2 where t1.some_column = t2.some_column |
It now needs to be:
|
|
select t1.id , t2.some_column from some_table as t1 inner join another_table as t2 on t1.some_column = t2.some_column |
We’ve identified the following files that frequently need to be updated: catalog/index.php There are four complex queries in this file that need to be updated as follows. The queries are shown in the order that they appear in the code. PRODUCTS BY MFG + CATEGORY Change from:
|
|
$listing_sql = "select " . $select_column_list . " pd.products_notes, p.products_packing_info, pd.products_description, p.products_id, p.products_model, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS . " m, " . TABLE_CATEGORIES_DESCRIPTION . " cd, " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where p.products_status = '1' and c.categories_id = p2c.categories_id and c.categories_id = cd.categories_id and p.manufacturers_id = m.manufacturers_id and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$HTTP_GET_VARS['filter_id'] . "'"; |
to:
|
|
$listing_sql = "select " . $select_column_list . " pd.products_notes, p.products_packing_info, pd.products_description, p.products_id, p.products_model, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price " . "from " . TABLE_PRODUCTS . " p " . "INNER JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c ON p.products_id = p2c.products_id " . "INNER JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd ON pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' " . "INNER JOIN " . TABLE_MANUFACTURERS . " m ON p.manufacturers_id = m.manufacturers_id " . "INNER JOIN " . TABLE_CATEGORIES . " c ON c.categories_id = p2c.categories_id " . "INNER JOIN " . TABLE_CATEGORIES_DESCRIPTION . " cd ON c.categories_id = cd.categories_id " . "LEFT JOIN " . TABLE_SPECIALS . " s on p.products_id = s.products_id " . "where p.products_status = '1' and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "' and p2c.categories_id = '" . (int)$HTTP_GET_VARS['filter_id'] . "'"; |
PRODUCTS BY MFG Change from:
|
|
$listing_sql = "select " . $select_column_list . " pd.products_notes, p.products_packing_info, pd.products_description, p.products_id, p.products_model, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price ". "from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_CATEGORIES_DESCRIPTION . " cd, " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_MANUFACTURERS . " m left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where p.products_status = '1' and c.categories_id = p2c.categories_id and c.categories_id = cd.categories_id and p.products_id = p2c.products_id and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "' and p.manufacturers_id = m.manufacturers_id and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "'"; |
to:
|
|
$listing_sql = "select " . $select_column_list . " pd.products_notes, p.products_packing_info, pd.products_description, p.products_id, p.products_model, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price " . "from " . TABLE_PRODUCTS . " p " . "INNER JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd ON pd.products_id = p.products_id AND pd.language_id = '" . (int)$languages_id . "' " . "INNER JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c ON p.products_id = p2c.products_id " . "INNER JOIN " . TABLE_CATEGORIES . " c ON c.categories_id = p2c.categories_id " . "INNER JOIN " . TABLE_CATEGORIES_DESCRIPTION . " cd ON c.categories_id = cd.categories_id " . "INNER JOIN " . TABLE_MANUFACTURERS . " m ON p.manufacturers_id = m.manufacturers_id " . "left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id " . "where p.products_status = '1' and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "'"; |
PRODUCTS BY CATEGORY + MFG Change from:
|
|
$listing_sql = "select " . $select_column_list . " pd.products_notes, pd.products_description, p.products_packing_info, p.products_id, p.products_model, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS . " m, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES_DESCRIPTION . " cd, " . TABLE_CATEGORIES . " c left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where p.products_status = '1' and c.categories_id = cd.categories_id and p.manufacturers_id = m.manufacturers_id and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['filter_id'] . "' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and c.categories_id = p2c.categories_id and pd.language_id = '" . (int)$languages_id . "' and (p2c.categories_id = '" . (int)$current_category_id . "' or c.parent_id = '" . (int)$current_category_id . "')"; |
to:
|
|
$listing_sql = "select " . $select_column_list . " pd.products_notes, pd.products_description, p.products_packing_info, p.products_id, p.products_model, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price " . "from " . TABLE_PRODUCTS . " p " . "INNER JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c ON p.products_id = p2c.products_id " . "INNER JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd ON pd.products_id = p2c.products_id AND pd.language_id = '" . (int)$languages_id . "'" . "INNER JOIN " . TABLE_MANUFACTURERS . " m ON p.manufacturers_id = m.manufacturers_id " . "INNER JOIN " . TABLE_CATEGORIES . " c ON c.categories_id = p2c.categories_id " . "INNER JOIN " . TABLE_CATEGORIES_DESCRIPTION . " cd ON c.categories_id = cd.categories_id " . "LEFT JOIN " . TABLE_SPECIALS . " s on p.products_id = s.products_id " . "where p.products_status = '1' and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['filter_id'] . "' and (p2c.categories_id = '" . (int)$current_category_id . "' or c.parent_id = '" . (int)$current_category_id . "')"; |
ALL PRODUCTS Change from: