A PHP script has been developed to connect to a database, retrieve all products, and save them in an XML file named products.xml. This file is stored in the same directory as the PHP script.
- Products: Sourced from the
producttable. - Product Descriptions: Found in the
product_descriptiontable. - Product Special Offers: Listed in the
product_specialtable.
- Model: Product model from the
product.modelfield. - Status: Indicates if the product is active (1) or inactive (0), from the
product.statusfield. - Name: Product name in three languages, stored in the
product_descriptiontable.- Name in Latvian (LV): Identified by language code 1
- Name in English (ENG): Identified by language code 2
- Name in Russian (RU): Identified by language code 3
- Description: Shortened product description in three languages (up to 200 characters with ellipsis), without breaking words in the middle. Found in the
product_descriptiontable.- Description in Latvian (LV): Language code 1
- Description in English (ENG): Language code 2
- Description in Russian (RU): Language code 3
- Quantity: Product stock quantity from the
product.quantity. - EAN: Product barcode from the
product.ean. - Image URL: Product image path from
product.image, prefixed with the base URL. - Date Added: Date of product addition in the format d-m-Y, from
product.date_added. - Price: Product price from
product.price. - Special Price: Discounted price from
product_specialif today's date (NOW) is less or equal todate_end.
- All prices are displayed with a 21% VAT included, rounded to two decimal places. Decimals are shown even if they are zero.
- The generated XML file
products.xmlfrom sample SQL data. - The script is compatible with MySQL version 5.7.39 and PHP 7.4.
Requirements: MySQL 5.7.39 and PHP 7.4
- Clone or download this Git repository.
- Create a MySQL database and import the
webdev_test.sqlfile into your MySQL database. - Open the project with a code editor (e.g., Visual Studio Code).
- In the
index.phpfile, fill in the following fields:$database_hostname: Your MySQL hostname or IP address (e.g., localhost).$database_username: Your MySQL username (e.g., root).$database_password: Your MySQL password, leave empty if not applicable.$database_name: Your MySQL database name (e.g., webdev).
- Run the script in the terminal from the directory containing
index.phpusing the command:
php index.php