Hi,
I run a couple of PHP-based websites on a server which until recently was running MySQL 4, but has now upgraded to 5.1. As a result of this upgrade, one of the site management scripts is no longer working and throws up an error at the query stage.
This is the query -
Code:
SELECT p.products_id, p.products_model, p.products_image, p.products_price, svetus.specials_new_products_price as vetus_special, subcvetus.categories_id as vetus_cat_id, svitesse.specials_new_products_price as vitesse_special, subcvitesse.categories_id as vitesse_cat_id FROM products p, categories_vsc subcvetus, products_to_categories_vsc ptocvetus left join specials_vsc svetus ON svetus.products_id = p.products_id, categories_vit subcvitesse, products_to_categories_vit ptocvitesse left join specials_vit svitesse ON svitesse.products_id = p.products_id WHERE p.products_id = ptocvetus.products_id AND ptocvetus.categories_id = subcvetus.categories_id AND p.products_id = ptocvitesse.products_id
AND ptocvitesse.categories_id = subcvitesse.categories_id
The database is used by two separate sites which sell the same products, but which are arranged into unique product category trees and have the capability to have unique special offer prices. This script is used to export the contents of the products database tables to a CSV file to allow the site owner to make modifications using Excel.
The script pulls off each product in turn, then the category it is in on each site, along with a special offer price for each site if it has one - hence the LEFT JOIN - ONs. This worked fine under MySQL 4, but as the syntax for LEFT JOINs is different in 5.1 it doesn't work now.
I know the statements need to be enclosed in parentheses, but no matter what I try I just get different flavours of error. The problem seems to be that you have two sequential LEFT JOINs, but both reference back to the same initial 'products' table reference in the query.
Any suggestions as to how I can fix this? The sites are structured so that potentially I could have several sites running from the same central database, so the query is built in blocks using PHP. I've looked at the script to see if I could get around the problem by querying the database in a different way, but it would involve virtually rewriting the whole script from scratch, and it's huge!
I would appreciate any suggestions or help.