For example, there is a table in the database:

alt text

in php, new data (users) for this table are entered into the array from the file, they need to be added there. But those users who are already in the table, but not in the array - need to be removed from the table, if there is no such user - then add, which are the same - leave.

I do not know what kind of request you need to make. update or replace - do not fit as far as I understood. Those. need to somehow combine insert and delete ? I do not know how to do it.

It’s only up to me to pull all the data from the table into an array, process everything in php and make the desired final array, then delete all the records from the table and write everything back to the new one ... but is this a bad way?

I don't really understand SQL . Tell me, please, how to do this?

  • Enter the file into the table (temporary - temporary), then delete it yourable where your user can choose and insert from the temporary table the missing insert into ... select ... where not exist (just don’t forget to give aliases to the table, so that the table in insert and select is not confused. And yet - what’s the screenshot in the question? Simply insert the text (even in Linux, even in Windows. In Windows, like the menu in corner of the window). - alexlz
  • clear, thanks, then I'll try :) - Comfmore
  • And how bad is the option to delete the data in the source table and then enter data from the file? Missing ones will be removed, new ones will be added, and old ones will be updated. And why the import comes from the file? So will it always be? How does the data get to the file? It may be worth working directly with the database, bypassing the file? - BOPOH
  • Well, at first I thought that if there are hundreds of rows in the table, then sending a bunch of add / remove requests is bad for performance, but now I realized that these are complex queries with subqueries - not better, so it will do. Well, I have depicted such a table with users for simplicity, in fact, instead of Vasya, Petit, etc. there are recorded conf. settings, but they are registered in the file, in fact, the question is already closed :) - Comfmore
  • one
    @Comfmore Well closed, so closed. But then sending a bunch of add / remove requests is bad for performance, but now I realized that these are complex queries with subqueries - not better, But it is difficult to agree with the fact that complex queries are "not better". It (complex queries) is spinning inside the sql-server, and the torment of the processor with a php-script should be heavier. - alexlz

0