The command reads a local XML file, processes its contents, and inserts the data into a database. It also handles errors and logs them accordingly.
- PHP >= 8.*
- Composer
- Laravel 11.x
- MySQL (or any other database of your choice)
-
Clone the repository:
git clone https://github.com/sudan94/xml_to_db_php.git cd xml_to_db_php
-
Install dependencies:
composer install
-
Create the
.env
file:cp .env.example .env
-
Update the
.env
file:Configure your database settings in the
.env
file. You can use any database as you need, just make sure to change in.env
file. Example, to use MySQL:DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=xml_db DB_USERNAME=root DB_PASSWORD=my-secrete-password
Make sure the MySQL database or any other are running:
-
Run migrations:
php artisan migrate
-
Run the import command:
php artisan import:xml ./feed/feed.xml
-
Check the database:
Verify that the data has been imported into the
items
table in your database.
-
Run the tests:
The project includes tests to verify the import command functionality. Run the tests using PHPUnit:
- Test file is in directory /tests/Feature/importXMLTest.php
php artisan test
Errors encountered during the import process are logged to the default log file specified in your Laravel application's logging configuration.
- log file can be found here storage/logs/laravel.log
- Main import function is in app\console\importXML.php
- Migration file is inside directory database\migrations