alexandre Posted November 8, 2022 Share Posted November 8, 2022 i have seen some example showing how to clone a table but not its content. so i am looking to keep the data from the cloned table as historical values. anyone have an idea how to do that ? Quote Link to comment https://forums.phpfreaks.com/topic/315499-i-would-like-to-know-the-most-effective-way-in-your-opinions-to-copy-a-table-and-its-content-using-php/ Share on other sites More sharing options...
requinix Posted November 8, 2022 Share Posted November 8, 2022 How to do what, exactly? Copy the structure and data of a table to a new table? Quote Link to comment https://forums.phpfreaks.com/topic/315499-i-would-like-to-know-the-most-effective-way-in-your-opinions-to-copy-a-table-and-its-content-using-php/#findComment-1602291 Share on other sites More sharing options...
alexandre Posted November 8, 2022 Author Share Posted November 8, 2022 (edited) 9 minutes ago, requinix said: How to do what, exactly? Copy the structure and data of a table to a new table? yes and after that i would drop and create a new table based on the copied structure to make a new round start from zero. so i would keep a clone of the previous round for historical values and keep going with the events. its just that i need everything to be automated so i need to do it with php Edited November 8, 2022 by alexandre Quote Link to comment https://forums.phpfreaks.com/topic/315499-i-would-like-to-know-the-most-effective-way-in-your-opinions-to-copy-a-table-and-its-content-using-php/#findComment-1602293 Share on other sites More sharing options...
requinix Posted November 8, 2022 Share Posted November 8, 2022 Actually you need to do it with SQL. PHP can be used to run that SQL, but PHP isn't going to be creating tables or copying data. If the table is simple and not used frequently then you rename the table and create a new blank one. If it has things like triggers or is being used a lot then create a blank table like the old one, which I think you said you know how to do, then do an INSERT...SELECT query. Quote Link to comment https://forums.phpfreaks.com/topic/315499-i-would-like-to-know-the-most-effective-way-in-your-opinions-to-copy-a-table-and-its-content-using-php/#findComment-1602294 Share on other sites More sharing options...
alexandre Posted November 8, 2022 Author Share Posted November 8, 2022 1 minute ago, requinix said: Actually you need to do it with SQL. PHP can be used to run that SQL, but PHP isn't going to be creating tables or copying data. If the table is simple and not used frequently then you rename the table and create a new blank one. If it has things like triggers or is being used a lot then create a blank table like the old one, which I think you said you know how to do, then do an INSERT...SELECT query. yeah you are right i could probably make a collumn ,a tiny int based on 1 and 0 and if my conditions are met then the 1 or 0 can be used to target the data to insert.. am i right ? Quote Link to comment https://forums.phpfreaks.com/topic/315499-i-would-like-to-know-the-most-effective-way-in-your-opinions-to-copy-a-table-and-its-content-using-php/#findComment-1602295 Share on other sites More sharing options...
requinix Posted November 8, 2022 Share Posted November 8, 2022 1 minute ago, alexandre said: yeah you are right i could probably make a collumn ,a tiny int based on 1 and 0 and if my conditions are met then the 1 or 0 can be used to target the data to insert.. am i right ? ...why? Do you not want to copy the whole table? Quote Link to comment https://forums.phpfreaks.com/topic/315499-i-would-like-to-know-the-most-effective-way-in-your-opinions-to-copy-a-table-and-its-content-using-php/#findComment-1602296 Share on other sites More sharing options...
alexandre Posted November 8, 2022 Author Share Posted November 8, 2022 Just now, requinix said: ...why? Do you not want to copy the whole table? thats another thing i wanted to ask about performance is it faster to just pull the whole table or to reduce the amount of data processes? i could just aim for the data i want? i am not sure about that anymore but i am trying to see this with a high traffic scale just to ensure that it is prepared to every eventuality .. Quote Link to comment https://forums.phpfreaks.com/topic/315499-i-would-like-to-know-the-most-effective-way-in-your-opinions-to-copy-a-table-and-its-content-using-php/#findComment-1602297 Share on other sites More sharing options...
requinix Posted November 8, 2022 Share Posted November 8, 2022 29 minutes ago, alexandre said: thats another thing i wanted to ask about performance is it faster to just pull the whole table or to reduce the amount of data processes? i could just aim for the data i want? i am not sure about that anymore but i am trying to see this with a high traffic scale just to ensure that it is prepared to every eventuality .. "High traffic" as in being written to frequently? Then you have a small problem of trying to decide what rows in the table you want to archive - after all, a bunch of them are being added all the time. Or, if it's being read from frequently, how are you going to make sure you don't pulls rows out of the table when something wants to read them? I feel like you have some questions here that need to be answered before you can do much more... Quote Link to comment https://forums.phpfreaks.com/topic/315499-i-would-like-to-know-the-most-effective-way-in-your-opinions-to-copy-a-table-and-its-content-using-php/#findComment-1602299 Share on other sites More sharing options...
alexandre Posted November 8, 2022 Author Share Posted November 8, 2022 1 minute ago, requinix said: "High traffic" as in being written to frequently? Then you have a small problem of trying to decide what rows in the table you want to archive - after all, a bunch of them are being added all the time. Or, if it's being read from frequently, how are you going to make sure you don't pulls rows out of the table when something wants to read them? I feel like you have some questions here that need to be answered before you can do much more... i am thinking about making the two events running with a timer set for 5 days , then take two days to let people claim their rewards if they didnt when the timer goes on again the prizes will be sent to another participant(i dint figured out yet how to make the balances update automaticly without the user being on the actual page ). so long story short, this weekend with the timer off will be used to make updates and everything that needs to be done like creating a new round for the events. but this is more to give a mental break to the users since all of this looks like gambling games, i dont want people to go addicted ... Quote Link to comment https://forums.phpfreaks.com/topic/315499-i-would-like-to-know-the-most-effective-way-in-your-opinions-to-copy-a-table-and-its-content-using-php/#findComment-1602300 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.