Integrate prestashop database with local database - php

I was looking around and couldn't find an answer for this question. If however, it is duplicated in some way, I apologise.
My problem is: I have a physical store, which has a accounting program with some database where my products are. I now created a store with prestashop and wanted to synchronise both of them.
I want to be able to add a REF to my prestashop and take every field from my LOCAL DB (except images and descriptions); I also want to synchronise the STOCKS in "real time".
My idea is having a "middle DB" which takes requests and updates the other 2 DB, as such:
Prestashop DB <-> MIDDLE DB <-> Local DB
My middle DB would have the REFs and Quantities for all the products and check if the latter field is changed in either DB, let's say every 2 mins, to then update the database that did NOT perform the request.
How difficult is it to do this? How can I connect to both databases, using python, c# or c++ and perform such tasks?
I'm using prestashop 1.6. and I have access to my database via PHPmyAdmin.
Thank you!

Related

How to use a variable to assign a database to each user in Laravel 5.3 in LAMP?

i have a little application for stock control in a shop wich is running in my online homemade server (lamp), i made my web app with laravel, now i have to use it to control more shops, so my idea is that when a user login in the app, he only can access to his own database, so i think i have to pass a variable with the databasename that correspond to every specific shop. how can i do that? is it right to create a virtualhost for each shop(now it could be 6 but can increase in the future)? or should i use one virtualhost and resolve the database assignment programatically in the webapp? all suggestions are welcome. thanks in advance
I am not a pro with laravel by any stretch however i imagine There is a couple of ways you could do this, That being said you should consider security issues when assigning a database variable / connection based on the users values.
An example would be to create a database table that holds each shops database name, That way you can make a request to the database and request the database name for that specific shop.
ID | Shop_Database_name
-----+-----
1 | myshop1
2 | myshop2
3 | myshop3
Then you can build your database connection based on the shop_database_name stored in a master table.
DB::select('shop_database_name')->where('id', $shop->id)->first();
// Now you will build a database connection using something like:
$shopDatabase = DB::connection('shop_database_name')->select(...);
You can also pre-configure your config/database.php with multiple databases for each shop however if you have many shops sign up this would not be the best approach and I would recommend you have an overall table that holds all your database names for each shop.
If I am on the wrong path feel free to let me know and i will try to help where I can.

Best way to update data in mysql online database

I have an online sql database with a few tables for users matches and bets. When I update the result of any game, I need the status of all bets containing that game in the bet table to be updated. So for example if I update game 8 with the result home win I need all bets which have game 8 in them to be updated as either lost, won or still open.
The way I do this currently is that when the user turns on my android app, I retrieve all the information about the games and all the information about the user's bets using asynctasks. I then do some string comparisons in my app and then I update the data in my database using another asynctask. The issue is that this wastes a lot of computation time and makes my app UI laggy.
As someone with minimal experience with php and online databases, I'd like to ask is there a way to carry out these things in the database itself either periodically (every 3 hours for example) or whenever the data in the gamestable is changed using a php file for example which is automatically run?
I tried looking for some kind of onDataChanged function but couldn't find anything. I'm also not sure how to make a php file run and update data without getting the app involved.
Another idea I had was to create a very simple app which I wouldn't distribute to anyone but just keep on my phone with an update button which I could press and trigger a php file to carry out these operations for all users in my database.
I would appreciate some advice on this from someone who has experience.
Thanks :).
You can easily execute php script periodically if your hosting provider supports script executors like Cron.
About updating game status multiple times, first check tables engine. If you are using engine like InnoDB you can create relationship between those tables, so updating status of one row will affect all connected to them.

Data input from one database to a remote database

I'm making a website for an e-commerce purpose. On the main page there will be a permanent text-block or a featured article, which is going to display information about latest money transactions.
For security reasons I want to hide the source where this information is coming from. So I decided to create 2 sites:
a) "Main Site" (MS): will be a fully custom site with an engine, which will be responsible to deal with and handle financial transactions. This site will contain all financial data and will be known/accessible only for limited people.
b) "Customer Site" (CS): will provide basic information along with "Latest transaction" page.
Main point is that "Latest transaction" on CS will be just a static copy of "latest" table in MS database and will not be available to be tracked back, as it will be uploaded/input from MS side each time when there is a new transaction. I presume that even if someone dumps the CS database, he/she will only be able to get a plain-text, without reaching the core database in MS. Because data input will be one-way from MS to CS.
Here is the draft scheme how I assume it to be, but don't know how to do:
Database-to-Database: to write a custom php file, which will be triggered after a new transaction and copy "latest" table values from MS database to a "latest" table in CS database.
Thanking in advance for any ideas, guides and especially for inputs.
If both db's are sql server, give MS permission to write to CS. Then write a trigger on MS that populates CS according to your requirements.
php involvement is unnecessary.

Update a database on server from multiple local databases

I am building a web-based ERP application for the retail industry using PHP and MySQL. I am going to have different local databases and one on the server(same structure). What I plan to do is run this app in localhost in different stores and at the end of the day update the database on the server from different localhosts in different stores.
Remember, I would like to update the database on the server based on the sequence queries run in different databases.
Can anyone please help me with this?
Thank you.
Perhaps link to your main database from the localhost sites to begin with? No need to update at the end of the day, every change that's made to the database is simply made to the database with no "middle men", so to speak. If you need the local databases separate, run the queries on both at once?
Note: I'm unfamiliar with how an ERP application works, so forgive me if I'm way off base here.
You may have to log every insert/update/delete sql requests in a daily file with a timestamp of your request on local databases.
Example :
2012-03-13 09:15:00 INSERT INTO...
2012-03-13 09:15:02 UPDATE MYTABLE SET...
2012-03-13 09:15:02 DELETE FROM...
...
Then send your log files daily on main server, merge all files, sort them to keep execution order and read new file to execute request on main database.
However, it's a curious way to do thing on ERP application. A product stock information can't be merged, it's a common information, be careful with this kind of data.
You can't use autoincrement with this process, this will cause duplicate key on some request or update requests on bad records.

Web architecture - how to save and restore DB snapshot efficiently

I need some advices on the best way to create/save/restore database snapshots for a website backend.
Here are the technical details (but I guess answers can be API independant) :
PHP : 5.3
PHP framework : Kohana 3.*
DB : MySQL 5.1
My webapp can be compared to a simple stock managment tool. The DB contains products with prices. At some point, users perform actions on these products (eg an order). At this moment, a PARTIAL snapshot of the DB is produced with only the related items. Later, in the main DB, products may be deleted or their price might change.
My goal is to store these snapshots, then, later, restore them using the code written for the full DB, to minimize code development and complexity.
As my DB is originally in MySQL, I plan to dump parts of the DB in a text file and zip it. To restore it, unzip, and reinject it in another DB (to not override items with the same names whose attributes have changed).
Is this an correct way to create and store parts of a DB? Or do smart designs handle that more efficiently?
Kohana specific : How to deal with ORM and multiple DB connections ? Objects are bound to only one DB. The default DB conection seems to be specfied in the session. Unfortunatelly, only one session seems to be allow at a time...
Thanks!
Have a look at Minion task migrations https://github.com/kohana-minion/tasks-migrations

Categories